hrbust 哈理工oj 2113 Count【STL水题】
2016-03-07 16:08
399 查看
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<stdio.h>
#include<string.h>
#include<iostream>
#include<map>
using namespace std;
char a[1005];
int ans[1000005];
int output[1000005];
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(ans,0,sizeof(ans));
memset(output,0,sizeof(output));
map<string,int >s;
int cont=1;
for(int i=0;i<n;i++)
{
scanf("%s",a);
if(s[a]==0)
{
s[a]=cont;
cont++;
ans[s[a]]=1;
}
else
{
ans[s[a]]++;
}
}
for(int i=1;i<=100005;i++)
{
if(ans[i])
output[ans[i]]++;
}
for(int i=1;i<=100005;i++)
{
if(output[i])
printf("%d %d\n",i,output[i]);
}
}
}
相关文章推荐
- 排序算法:希尔排序
- Gallery与ImageSwitch实现照片的预览功能
- 从这里开始,零度的追逐
- 第二章笔记
- C语言中改变字体颜色和背景的方法
- QT学习第一节
- 排序算法:希尔排序
- 简析类与对象,组合类,派生类的初始化过程
- NestedScrollView嵌套ViewPager
- Win8.1系统安装软件时报错called runscript when...解决方法
- NestedScrollView嵌套ViewPager
- js数组排序神器
- PAT (Basic Level)1029. 旧键盘
- if语句的用法及其案例
- postgresql Delete+ join
- bigbluebutton开发
- Java类与对象的一些想法
- graphx中Pregel函数详解
- selenium 'NoSuchElementException'
- wayland&weston