HDU1219--AC Me

AC Me

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 11549    Accepted Submission(s): 5123

Problem Description

Ignatius is doing his homework now. The teacher gives him some articles and asks him to tell how many times each letter appears.

It‘s really easy, isn‘t it? So come on and AC ME.

Input

Each article consists of just one line, and all the letters are in lowercase. You just have to count the number of each letter, so do not pay attention to other characters. The length of article is at most 100000. Process to the end of file.

Note: the problem has multi-cases, and you may use "while(gets(buf)){...}" to process to the end of file.

Output

For each article, you have to tell how many times each letter appears. The output format is like "X:N".

Output a blank line after each test case. More details in sample output.

Sample Input

hello, this is my first acm contest!
work hard for hdu acm.

Sample Output

a:1
b:0
c:2
d:0
e:2
f:1
g:0
h:2
i:3
j:0
k:0
l:2
m:2
n:1
o:2
p:0
q:0
r:1
s:4
t:4
u:0
v:0
w:0
x:0
y:1
z:0

a:2
b:0
c:1
d:2
e:0
f:1
g:0
h:2
i:0
j:0
k:1
l:0
m:1
n:0
o:2
p:0
q:0
r:3
s:0
t:0
u:1
v:0
w:1
x:0
y:0
z:0

解析:感觉这是一道非常基础但是自我感觉非常适合入门的字符串的题目,我是在杭电ACM Steps中进阶的时候做的,感觉不错所以拿来博客,记录一下,与众人分享哈!

#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
using std::endl;
using std::cin;
using std::cout;
using std::string;
int result[26];
int main()
{
#ifdef LOCAL
	freopen("input.txt" , "r" , stdin);
#endif
	string str;
	while(getline(cin , str))
	{
		memset(result , 0 , sizeof result);
		for(int i=0; i<str.length();++i)
		{
			if(isalpha(str[i]))
			{
				result[str[i]-'a']++;
			}
		}
		for(int i=0;i<26;++i)
		{
			cout << (char)('a'+i) << ":" <<result[i] << endl;
		}
		cout << endl;
	}
	return 0;
}

HDU1219--AC Me,布布扣,bubuko.com

时间: 2024-08-07 02:56:50

HDU1219--AC Me的相关文章

诬柯司戎苡xwkx05na97tu1llqac

http://www.qiushibaike.com/tag/%e7%a3%90%e7%9f%b3%e6%b0%b0%e5%8c%96%e9%92%a0%e5%93%aa%e9%87%8c%e6%9c%89%e5%8d%96%2b%ef%bd%91%ef%bc%92%ef%bc%98%ef%bc%95%ef%bc%98%ef%bc%92%ef%bc%99%ef%bc%91%ef%bc%92%ef%bc%90.http://www.gxxc.gov.cn/Town/TownDetails?id=9

斡密勐芡眼n16mt3esra161fqo

http://www.gxxc.gov.cn/Town/TownDetails?id=94210&town=%e5%bb%ba%e5%be%b7%e5%93%aa%e9%87%8c%e6%9c%89%e6%b0%b0%e5%8c%96%e9%92%be%e4%b9%b0%2b%ef%bd%91Q%e2%92%89%e2%92%8f%e2%92%8c%e2%92%8f%e2%92%89%e2%92%90%e2%92%88%e2%92%89O.http://www.gxxc.gov.cn/Town/

暑假集训day9补充(AC自动机)

推荐网站http://blog.csdn.net/niushuai666/article/details/7002823 AC自动机嘛,此AC(aho-corasick)非彼AC(Accepted). 我也不是很会解释 有一题是必须打的hdu2222. #include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; const int mn=

ac自动机基础模板(hdu2222)

In the modern time, Search engine came into the life of everybody like Google, Baidu, etc. Wiskey also wants to bring this feature to his image retrieval system. Every image have a long description, when users type some keywords to find the image, th

Linux DHCP通过OPTION43为H3C的AP下发AC地址

对于DHCP服务,可以在很多平台上进行设置.那么这里我们就主要讲解一下在Linux DHCP服务器上通过option 43实现H3C的AP自动联系AC注册的相关内容.原来的DHCP Server是放在交换机上的,但因为近期准备改动一下网络拓扑,所以要把DHCP Server迁移,操作系统用的是RHEL5.3,DHCP版本3.05 打H3C的800电话,二线工程师说没有在Linux下的DHCP配过,要我去看文档,文档里有交换机做dhcp server和windows做dhcp server的配置实

HDU 2825 Wireless Password AC自动机+dp

训练赛第二场的I题,上完体育课回来就把这题过了,今天训练赛rank1了,还把大大队虐了,而且我还过了这道题 (虽然我也就过了这道题...),第一次在比赛中手写AC自动机还带dp的,心情大好. 给一个字符串集合,求包含该集合超过K个字符的,长度为L的字符串的个数. 显然是在AC自动机上跑dp,设dp[u][L][k]表示当前在结点u,还要走L步,当前状态为k的个数.一开始第三维表示的是包含k个字符串,但是题目要求不含重复的,那就只能状压了.转移为dp[u][L][k]+=dp[v][L-1][nk

LightOJ 1427 -Repository(ac自动机)

题意: 求每个模式串在母串中出现的次数 #include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <string> #include <cctype> #inclu

HDU 2896-病毒侵袭(ac自动机)

题意: 给定多个模式串,每给一个母串,输出包含模式串的编号,最后输出包含模式串的母串的数量. 分析: ac自动机模板 #include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <st

hdu2222 Keywords Search &amp; AC自动机学习小结

传送门:http://http://acm.hdu.edu.cn/showproblem.php?pid=2222 思路:AC自动机入门题,直接上AC自动机即可. 对于构建AC自动机,我们要做的只有三件事: 1)构建字典树 2)构建失败指针 3)构建trie图(这道题好像不做这一步也能A...但是这一步不做是会被卡成O(n^2)的...) 1)第一步还是比较好理解的 根是虚根,边代表字母,那么根到终止节点的路径就是一个字符串,这样对于前缀相同的字符串我们就可以省下存公共前缀的空间. 加入一个模式

hdoj 2896 病毒侵袭(AC自动机)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2896 思路分析:题目为模式匹配问题,对于一个给定的字符串,判断能匹配多少个模式:该问题需要静态建树,另外需要对AC自动机的模板加以修改, 对于每个匹配的模式的最后一个单词的fail指针指向root,即可实现一个字符串进行多次模式匹配: 代码如下: #include <queue> #include <cstdio> #include <cstring> #include &