SDUT 1250 统计元音
来源:互联网 发布:网络客服岗位要求 编辑:程序博客网 时间:2024/06/05 08:16
Problem Description
统计每个元音字母在字符串中出现的次数。
Input
输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串。
Output
对于每个测试实例输出5行,格式如下:
a:num1
e:num2
i:num3
o:num4
u:num5
多个测试实例之间由一个空行隔开。
Example Input
2aeioumy name is ignatius
Example Output
a:1e:1i:1o:1u:1a:2e:1i:3o:0u:1
正确答案:
#include <iostream>#include <cctype>#include <cstring>#include <cstdio>using namespace std;int main(){void change(char str[], int str2[], int m);int n, m, str2[5];char str1[5] = {'a', 'e', 'i', 'o', 'u'};char str[100];cin >> n;while (n--){gets(str);if(str[0] == '\0')gets(str);//这里耽误了很多时间,如果没有这两行代码,输入n的值后,回车键会读入字符数组str中。加判断的意义在于第二次及以后循环时不用再输入n值,此时输入的字符串直接存入字符数组就好,该输入不需要。memset(str2, 0, sizeof(str2));m = strlen(str);change(str, str2, m);for (int i = 0; i < 5; i++){cout << str1[i] << ":" << str2[i] << endl;}if(n != 0)cout << endl;}return 0;}void change(char str[], int str2[], int m){for (int i = 0; i < m; i++){if(str[i] == 'a')str2[0]++;else if(str[i] == 'e')str2[1]++;else if(str[i] == 'i')str2[2]++;else if(str[i] == 'o')str2[3]++;else if(str[i] == 'u')str2[4]++;}}
阅读全文
0 0
- SDUT-1250 统计元音
- SDUT 1250 统计元音
- 统计元音 (sdut oj)
- SDUTOJ 1250 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 统计元音
- 读书:海明威的《老人与海》
- 【Java】统计文件中各单词数量
- 再谈链接、静态链接、动态链接
- centos7.3安装zabbix过程遇到的错误与排错方法
- 从输入URL到页面加载发生了什么
- SDUT 1250 统计元音
- Spring与Struts2整合:执行流程
- 2017暑假训练第二十一天
- 浙大PAT甲级-1061
- C++笔记_03面向对象1,2
- 剑指offer第六题(数组)
- Python爬虫——利用PhantomJS下载动态加载图片
- 面向对象的基本概念、基本特征、设计原则
- 数组中重复的数字