单词统计
单词统计
单词统计 | SDUT
#include <stdio.h>
#include <string.h>
int main(){
char a[100];
int count=0;
int flag=0;
gets(a);
for(int i=0;i<strlen(a);i++){
if(a[i]==' '){
flag=0;//将flag一直更新只要等于空格就一直赋值为0。
}
else if(flag==0){
flag=1;
count++;//单词更新且改变flag
}
}
printf("%d\n",count);
return 0;
}