AtCoder 155 C Poll

Poll

时间限制: 1 Sec  内存限制: 128 MB

题目描述

We have N voting papers. The i-th vote (1≤i≤N) has the string Si written on it.
Print all strings that are written on the most number of votes, in lexicographical order.

Constraints
·1≤N≤2×105
·Si (1≤i≤N) are strings consisting of lowercase English letters.
·The length of Si (1≤i≤N) is between 1 and 10 (inclusive).

输入

Input is given from Standard Input in the following format:

N
S1
:
SN
 

输出

Print all strings in question in lexicographical order.

样例输入

【样例1】
7
beat
vet
beet
bed
vet
bet
beet
【样例2】
8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
【样例3】
7
bass
bass
kick
kick
bass
kick
kick
【样例4】
4
ushi
tapu
nichia
kun

样例输出

【样例1】
beet
vet
【样例2】
buffalo
【样例3】
kick
【样例4】
kun
nichia
tapu
ushi

提示

样例1解释
beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.

题解

这本是一道简单的题,用个map就可以解决的事儿,但是一台优(la)秀(ji)的评测机完美的卡住了这道题。怎么不超时呢?cin关闭同步,开O3,输出用putchar,一套组合拳。

 1 #pragma GCC optimize(3,"Ofast","inline")
 2 #include<map>
 3 #include<cstdio>
 4 #include<string>
 5 #include<cstring>
 6 #include<iostream>
 7 #include<algorithm>
 8 using namespace std;
 9 const int N = 200009;
10 int n, MN, cnt;
11 string g[N];
12 map<string, int>f;
13 map<string, bool>p;
14 int main()
15 {
16     std::ios::sync_with_stdio(false);
17     cin >> n;
18     for(int i = 1; i <= n; i++)
19     {
20         cin >> g[i];
21         f[g[i]]++;
22     }
23     for(map<string, int>::iterator it = f.begin(); it != f.end(); it++)
24         MN = max(MN, it->second);
25     sort(g+1, g+n+1);
26     int m;
27     for(int i = 1; i <= n; i++)
28     {
29         if(f[g[i]] != MN) continue;
30         m = g[i].length();
31         for(int j = 0; j < m; j++)
32             putchar(g[i][j]);
33         putchar('\n');
34         f[g[i]] = 0;
35     }
36     return 0;
37 }
View Code

 

posted @ 2020-03-14 19:27  Johnny-English  阅读(246)  评论(0编辑  收藏  举报