一道C++题目,急求解答!在线等!!!

第六小题,请别用复杂的函数什么的,我是新手。真的非常感谢能帮忙解答的大佬。

#include<iostream>
#include<string.h>
using namespace std;
main()
{   char a[1000];
    int i,max,l,n;
    while(1){
        gets(a);
        max=0;l=0;n=0;
        if(a[0]==' ') l=0;
        else l=1;
        for(i=0;i<strlen(a);i++)
            if(a[i]==' '){
             n=0;
             if(a[i+1]!=' '&&a[i+1]!='\0')
             l++;
        }
        else{
    n++;
    if(max<n) max=n;
    }
        cout<<"单词个数:"<<l<<endl;
cout<<"最长单词长度:"<<max<<endl;
}
}

如图所示,望采纳。。。。。。

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答