C++程序设计 写一个scanner,例如输入 I am a student
写一个scanner,例如输入Iamastudent输出Iamastudent统计单词个数4...
写一个scanner,例如输入 I am a student
输出 I
am
a
student
统计单词个数4 展开
输出 I
am
a
student
统计单词个数4 展开
1个回答
2013-08-10
展开全部
#include<iostream>
using namespace std;
int main(void)
{
char scanner[100];
int n = 0;
bool check = false;
cout<<"Enter a sentence:"<<endl;
gets(scanner);
cout<<"***********************"<<endl;
for(int i = 0; i<strlen(scanner); i++)
{
if(scanner[i]==' ')
{
if(check)
{
cout<<endl;
n++;
check = false;
}
}
else
{
check = true;
cout<<scanner[i];
}
}
cout<<endl<<"共有单词 "<<n+1<<"个!"<<endl;
return 0;
} ******本程序可以输入不规范的英语句子********
using namespace std;
int main(void)
{
char scanner[100];
int n = 0;
bool check = false;
cout<<"Enter a sentence:"<<endl;
gets(scanner);
cout<<"***********************"<<endl;
for(int i = 0; i<strlen(scanner); i++)
{
if(scanner[i]==' ')
{
if(check)
{
cout<<endl;
n++;
check = false;
}
}
else
{
check = true;
cout<<scanner[i];
}
}
cout<<endl<<"共有单词 "<<n+1<<"个!"<<endl;
return 0;
} ******本程序可以输入不规范的英语句子********
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询