HLG 2113 Count (C++ --- 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;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值