# 2027 ( 统计元音 ) :hash应用
Problem Description
统计每个元音字母在字符串中出现的次数。
Input
输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串。
Output
对于每个测试实例输出5行,格式如下:
a:num1
e:num2
i:num3
o:num4
u:num5
多个测试实例之间由一个空行隔开。
请特别注意:最后一块输出后面没有空行:)
Sample Input
2
aeiou
my name is ignatius
一遍hash即可
AC代码①
#include<iostream>
#include<string>
using namespace std;
int main() {
string s;
int n;
while (cin >> n) {
getchar();
while (n--) {
getline(cin, s);
int a = 0, e = 0, i = 0, o = 0, u = 0;
for (int j = 0; j < s.length(); ++j) {
if (s[j] == 'a')++a;
if (s[j] == 'e')++e;
if (s[j] == 'i')++i;
if (s[j] == 'o')++o;
if (s[j] == 'u')++u;
}
printf("a:%d\n", a);
printf("e:%d\n", e);
printf("i:%d\n", i);
printf("o:%d\n", o);
printf("u:%d\n", u);
if (n)
cout << endl;
}
}
return 0;
}
AC代码②
#include<bits/stdc++.h>
using namespace std;
map<char, int>mp;
int main() {
int t;
string s;
cin >> t;
while (t--) {
//清除回车
getchar();
//手动清零,不然如果没有字母出现则最后打印就无法出现该字母
mp['a'] = 0;
mp['e'] = 0;
mp['i'] = 0;
mp['o'] = 0;
mp['u'] = 0;
getline(cin, s);
for (auto c : s) {
mp[c]++;
}
for (auto x : mp) {
if (x.first == 'a' || x.first == 'e' || x.first == 'i' || x.first == 'o' || x.first == 'u') {
cout << x.first << ":" << x.second << endl;
}
}
cout << endl;
}
return 0;
}
# 2027 ( 统计元音 ) :hash应用的更多相关文章
- hdu 2027 统计元音
统计元音 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDOJ 2027 统计元音
Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output 对于每个 ...
- hdu 2027统计元音
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2027 思路:主要考察gets()函数用法,能够接受输入的空格,如果用%s或是cin>>st ...
- ytu 1939:统计元音(水题)
统计元音 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 68 Solved: 33[Submit][Status][Web Board] Descrip ...
- HDOJ2027统计元音
统计元音 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- LeetCode 5216. 统计元音字母序列的数目(Java)DP
5216. 统计元音字母序列的数目 给你一个整数 n,请你帮忙统计一下我们可以按下述规则形成多少个长度为 n 的字符串: 字符串中的每个字符都应当是小写元音字母('a', 'e', 'i', 'o', ...
- 最新电Call记录统计-full hash join用法
declare @time datetime set @time='2016-07-01' --最新的电Call记录统计查询--SELECT t.zuoxi1,t.PhoneCount,t.Phone ...
- HDU_2027——统计元音
Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output ...
- HDU2027:统计元音
Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output 对于每个 ...
- 统计元音(stringstream的-应用)
Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output ...
随机推荐
- The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission,iphone手机video标签报错
The request is not allowed by the user agent or the platform in the current context, possibly becaus ...
- 【布局技巧】Flex 布局下居中溢出滚动截断问题
在页面布局中,我们经常会遇到/使用这么一类常见的布局,也就是列表内容水平居中于容器中,像是这样: <ul class="g-contaner"> <li>& ...
- Pipeline模式应用
本文记录Pipeline设计模式在业务流程编排中的应用 前言 Pipeline模式意为管道模式,又称为流水线模式.旨在通过预先设定好的一系列阶段来处理输入的数据,每个阶段的输出即是下一阶段的输入. 本 ...
- MySQL按照日期查询
MySQL按时间查询 今天 select * from 表名 where TO_DAYS(时间字段名) = TO_DAYS(now()); 昨天 SELECT * FROM 表名 WHERE TO_D ...
- Oracle数据字典(各种视图、表)
数据字典是存放整个数据库实例重要信息的一组表,这些数据字典大部分都是SYS用户所有. 数据字典的构成 Oracle数据字典名称由前缀和后缀组成,使用下画线"_"连接.其代表的含义如 ...
- 【C++】关于全局变量和局部变量问题
1 #include <iostream> 2 using namespace std; 3 4 void func(void); 5 6 static int count = 10; 7 ...
- MySQL 数据目录
MySQL 的数据目录 1. MySQL 的主要目录结构 方式1:通过命令搜索 find / -name mysql 方式2(推荐):通过查看配置文件获取目录结构 vim /etc/my.cnf (重 ...
- 从零玩转设计模式之抽象工厂设计模式-chouxiangshejimoshi
title: 从零玩转设计模式之抽象工厂设计模式 date: 2022-12-08 16:05:03.28 updated: 2022-12-11 23:03:16.842 url: https:// ...
- ActiveMQ RCE CVE-2023-46604分析
一.漏洞触发点 org.apache.activemq.openwire.v12包下BaseDataStreamMarshaller类的createThrowable方法. package org.a ...
- 【MySql】数据库_MySql基础
yum install mysql mysql -u root -p 创建数据库 create database 数据库名; 查看所有数据仓库 show databases; 删除数据库 drop d ...