#include<iostream>
#include"string.h"
using namespace std;
int main()
{
char a[100];
int i, z=0;
cout << "请输入一个句子:" << endl;
cin.get(a,100,'\n');
for(i=0;a[i] != '\0'; i++)
{
if((a[i]!='?'&&a[i]!=' '&&a[i]!='?'&&a[i]!='.'&&a[i]!=';')&&(a[i+1]=='?'||a[i+1]=='.'||a[i+1]=='!'||a[i+1]==';'||a[i+1]==' '))
{
z++;
}
if(a[i]==' '&&a[i+1]==' ')
{
continue;
}
else
{
continue;
}
}
cout<<"There are "<<z<<" words in the line."<<endl;
return 0;
}
计算句子中的字符数
最新推荐文章于 2023-11-11 11:16:06 发布