STL之map模板

题目信息:

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<stdio.h>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
using namespace std;
int ans[100005];
int main()
{
	int n;
	int i,j,k;
	char a[25];
	while(~scanf("%d",&n))
	{
		map<string,int>mp;
		map<string,int>::iterator it;
		memset(ans,0,sizeof(ans));
		for(i=1;i<=n;i++)
		{
			scanf("%s",a);
			mp[a]++;
		 } 
		 for(it=mp.begin();it!=mp.end();it++)
		 {
		 	int cnt=it->second;
		 	ans[cnt]++;
		 }
		 for(i=1;i<=n;i++)
		 {
		 	if(ans[i]!=0)
		 	printf("%d %d\n",i,ans[i]);
		 }
	}
	return 0;
} 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值