第二周 任务三

来源:互联网 发布:淘宝网儿童公主裙 编辑:程序博客网 时间:2024/04/26 23:06

#include <iostream>
using namespace std;   
int main()   
{  
    char str[81],ch;     
    int i=0,num=0; 
    bool isWord=false;    
    gets(str); 
    ch=str[i]; 
    while(ch!='\0') 
    { 
        if (ch==' ') isWord=false;      
        else if (isWord==false)                 
            isWord=true,num++;  
        ++i; 
        ch=str[i]; 
    } 
    cout<<"there are "<<num<<" words in the line"<<endl;  
    return 0; 
}   

 

 

原创粉丝点击