Hust oj 2113 Count(Map)
2016-03-16 20:18
381 查看
Count | ||||||
| ||||||
Description | ||||||
Given a number of strings, can you find how many strings that appears T times? | ||||||
Input | ||||||
The input contains multiple test cases. Each case begins with a integer N(the number of strings you will get, N<=100000), followed by N lines, each consists of a string. The length of each string won't longer than 20. | ||||||
Output | ||||||
For each test case: There will be several lines. Echo line print two integers T and M, separated by a space. T represents the string appears T times, M represents there are M strings that echo string appears T times. Don't print T or M if M <= 0. The output is ordered by T, from small to large. | ||||||
Sample Input | ||||||
5 BBA BBA BEA DEC CCF | ||||||
Sample Output | ||||||
1 3 2 1 | ||||||
Source | ||||||
ACM-ICPC黑龙江省第九届大学生程序设计竞赛选拔赛(2) |
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<map> using namespace std; int ans[100005]; int main() { int n; int i,j,k; char a[50]; while(~scanf("%d",&n)) { map<string ,int>mapS; map<string,int >::iterator it; memset(ans,0,sizeof(ans)); for(i=1;i<=n;i++) { scanf("%s",&a); mapS[a]++; } for(it=mapS.begin();it!=mapS.end();it++) { int cnt=it->second; ans[cnt]++; } for(i=0;i<n;i++) { if(ans[i]!=0) printf("%d %d\n",i,ans[i]); } } }
相关文章推荐
- 用Matlab批量生成图片
- 封号、扣钱:谁来保证专车司机的利益?
- 金融业IT员工,在总行做软件开发,职业发展道路真的很窄吗?
- ZOJ 2853 Evolution【矩阵快速幂】
- const 在c中的用法
- C++中为什么要用虚函数、指针或引用才能实现多态?
- 试编写一个程序,输入一个字符串,统计其中有多少各单词?单词之间用空格分开
- 性能优化之布局优化
- android:taskAffinity与android:finishOnTaskLaunch之我见
- Hive——用户自定义函数(UDF)
- 学习进度表
- two sum
- svn命令行使用技巧
- 使用Eclipse时一些报错
- UI进阶——SQL数据库
- Python的高级Git库 Gittle_python_脚本之家
- centos7.0 安装字体库
- 这周的工作内容
- iOS之05-三大特性之封装
- LINUX内核设计与实现第三周读书笔记