题目描述
输入一个正整数 repeat (O-repeat<10),做repeat 次下列运算:
输入一行宇符,统计其中单词的个数。各单词之间用空格分隔,空格数可以是多个。
输入
见sample
输出
见sample
样例输入
3
Every night in my dreams
I see you I feel you
That is how I know you go on
样例输出
5
6
8
题目主要恶心在有多个空格!
#include<stdio.h>
#include<string.h>
int main()
{
int i,n,len,a,sum;
scanf("%d\n",&n);
for(i=0;i<n;i++)
{
char c[1000];
gets(c);
sum=0;
len=strlen(c);
if(c[0]!=' '){
sum++;
}
for(a=0;a<len;a++){
if(c[a]==' '&&c[a+1]!=' '&&c[a+1]!='\0'){
sum++;
}
}
printf("%d\n",sum);
}
return 0;
}