HDU-2027 统计元音

来源:互联网 发布:wifi自动切换软件 编辑:程序博客网 时间:2024/05/24 07:39

HDU-2027 统计元音

题目大意:统计一句英语语句中的元音字母 a,e,i,o,u 的个数(特别注意:最后一块输出后面没有空行)

Sample Input

2
aeiou
my name is ignatius
i want to get an accepted

Sample Output

a:1
e:1
i:1
o:1
u:1

a:2
e:1
i:3
o:0
u:1

解题思路:对每个字符进行判断。

#include <iostream>using namespace std;int main() {    char s[500];    while (gets_s(s) != NULL) {        int len = strlen(s);        if (s[0] >= 97 && s[0] <= 122)            s[0] -= 32;        for (int i = 0; i < len; i++) {            if (s[i] == 32 && (s[i + 1] >= 97 && s[i + 1] <= 122))                s[i + 1] -= 32;        }        cout << s << endl;    }    return 0;}
0 0
原创粉丝点击