您的位置:首页 > 其它

哈理工OJ 2113 Count(map计数)

2016-08-19 19:19 375 查看
题目链接:

http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2113

Count

Time Limit: 1000 MS Memory Limit: 32768 K

Total Submit: 119(61 users) Total Accepted: 67(58 users) Rating: Special Judge: No

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)

很简单的map问题,只需要扫两遍就OK了。

下面是AC代码:

#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;

int num[100005];
int main()
{
int n;
while(~scanf("%d",&n))
{
map<string,int>m;
string a[100005];
for(int i=0;i<n;i++)
{
cin>>a[i];
m[a[i]]++;
}
memset(num,0,sizeof(num));
for(int i=0;i<n;i++)
{
num[m[a[i]]]++;
m[a[i]]=0;
}
for(int i=1;i<=100000;i++)
{
if(num[i])
printf("%d %d\n",i,num[i]);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  哈理工OJ