Description
输入一字符串行,统计其单词个数
Input
长字符串
Output
单词个数。其前后不留空格,答案后不用换行回车
Sample Input
What is going on with you these days
Sample Output
8
Source:
#include<iostream> using namespace std; int N; char str[100000]; void count() { for(int i=0;str[i]!='/0';i++) { if(str[i]==' ') N++; while(str[i]==' ') { i++; } } N++; } int main() { gets(str); if(!strcmp(str,"/0")) { cout<<"0"; exit(1); } count(); cout<<N; }KEY:注意空格数量