P_166统计单词数

 1 //统计单词数 
 2 #include<iostream>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     char string[81];
 9     int i,num=0,word=0;
10     char c;
11     gets(string);
12     for(i=0;(c=string[i])!='';i++)//不是就继续执行循环 
13     {
14         if(c==' ')                //遇见空格,word为0,进入下一个条件 
15         {
16             word=0;
17         }
18         else if(word==0)          //出现空格,word为1 
19         { 
20             word=1;                
21             num++;
22          } 
23     }
24     cout<<num<<endl;
25     return 0;
26  } 

转载请说明出处!
原文地址:https://www.cnblogs.com/zengshangzhi/p/8779326.html