3942 - 3. 用gets函数输入一行字符,统计字符个数(即字符串长度)
用gets函数输入一行字符,统计字符个数(即字符串长度)。
Input
一行字符串
Output
字符串长度
Examples
Input
hello world!
Output
12
Solution C
#include<stdio.h> #include<string.h> int main() { char str[100]; gets(str); printf("%d\n",strlen(str)); return 0; }
Solution C++
#include<stdio.h> int main() { char a[100]; int i,n=0; gets(a); for(i=0;a[i];i++) n++; printf("%d",n); return 0; }