运用for语句循环来搜索元音字母,判断元音字母并在赋予特定值,让最后一次不输出换行,及判断该是否为最后一次项。
...
include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int o = 0;
while (o < n)
{
int b=0, c=0, d=0, e=0, f=0;
char a[1000];
cin >> a;
for (int i = 0; a[i] != 0; i++)
{
if (a[i] == 'a')
{
b++;
}
if (a[i] =='e')
{
c++;
}
if (a[i] == 'i')
{
d++;
}
if (a[i] == 'o')
{
e++;
}
if (a[i] == 'u')
{
f++;
}
}
cout << 'a' << ':' << b << endl;
cout << 'e' << ':' << c << endl;
cout << 'i' << ':' << d << endl;
cout << 'o' << ':' << e << endl;
cout << 'u' << ':' << f << endl;
if (o != n - 1)
{
cout << endl;
}
o++;
}
return 0;
}
...
网友评论