码迷,mamicode.com
首页 > 编程语言 > 详细

HLG 2113 Count (C++ --- map容器 基础题)

时间:2014-06-20 09:00:14      阅读:344      评论:0      收藏:0      [点我收藏+]

标签:map容器

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

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


比赛时写的代码:

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

map <string, int> mp;
map <string, int>:: iterator it;
int flag[100000];

int main()
{
    int n;
    string s;
    while(~scanf("%d", &n)) {
         mp.clear();
        for(int i=0; i<n; i++) {
            cin >> s;
            mp[s]++;
        }
        memset(flag, 0, sizeof(flag));
        //sort(mp.begin(), mp.end(); cmp);
        for(it=mp.begin(); it!=mp.end(); it++) {
            int mc = (*it).second;
            flag[mc]++;
        }
        for(int i=0; i<100000; i++) if(flag[i]) {
            cout << i << " " << flag[i] << endl;
        }
    }
    return 0;
}



HLG 2113 Count (C++ --- map容器 基础题),布布扣,bubuko.com

HLG 2113 Count (C++ --- map容器 基础题)

标签:map容器

原文地址:http://blog.csdn.net/keshacookie/article/details/28412683

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!