程序填空,不要改变与输入输出有关的语句。
输入一个正整数repeat (0<repeat<10),做repeat次下列运算:
输入一行字符,以回车结束,统计其中单词的个数。各单词之间用空格分隔,空格数可以是多个。
输入输出示例:括号内是说明
输入
2 (repeat=2)
Let's go to room 209.
Programming is fun
输出
count = 5 ("Let's go to room 209."中有5个单词)
count = 3 (" Programming is fun"中有3个单词)
<pre name="code" class="cpp">#include <stdio.h>
int main(void)
{
char c;
int count, word;
int repeat, ri;
scanf("%d", &repeat);
getchar();
for(ri = 1; ri <= repeat; ri++){
c = getchar();
count = 0;
word = 0;
while(c != '\n')
{
if(word == 1 && c == ' ')
{
count++;
word = 0;
}
if(c != ' ')
word = 1;
c = getchar();
}
if(word == 1) count++;
printf("count = %d\n", count);
}
}
程序填空,不要改变与输入输出有关的语句。输入一个正整数repeat (0<repeat<10),做repeat次下列运算:输入一行字符,以回车结束,统计其中单词的个数。各单词之间用空格分隔,空格数可以是多个。输入输出示例:括号内是说明输入2 (repeat=2)Let's go to room 209. Programming is fun输出count = 5