#include<iostream>
#include<string>
using namespace std;
int main()
{
unsigned int vowel = 0;
unsigned int consonant = 0;
unsigned int other = 0;
string ch;
cout << "请输入(退出请输入q):" << endl;
while ((cin>>ch))
{
//如果用户输入q,循环终止
if (ch.length() == 1 && ch[0] == 'q')
{
break;
}
//判断输入单词的首字母
if (isalpha(ch[0]))
{
if (ch[0] == 'a' || ch[0] == 'e' || ch[0] == 'i' || ch[0] == 'u' || ch[0] == 'o')
{
vowel++;
}
else
{
consonant++;
}
}
else
{
other++;
}
}
cout << "有"<<vowel <<"个元音打头的单词"<< endl;
cout << "有"<<consonant<<"个辅音打头的单词" << endl;
cout << other <<"个单词不属于这两类"<< endl;
system("pause");
return 0;
}
(C++)每次读取一个用户输入的单词,并分别指出以元音打头和以辅音打头以及不属于这两类的单词数量。
最新推荐文章于 2022-10-18 20:29:18 发布