众数问题
2015-07-29 21:31
253 查看
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) {
return p1.second < p2.second;
}
int main () {
int t;
scanf("%d", &t);
while (t--) {
map<int, int> m;
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int ans;
scanf("%d", &ans);
m[ans]++;
}
int num, sum = 0;
map<int, int>::iterator it = max_element(m.begin(), m.end(), cmp);
printf("%d %d\n", it -> first, it -> second);
}
return 0;
}
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) {
return p1.second < p2.second;
}
int main () {
int t;
scanf("%d", &t);
while (t--) {
map<int, int> m;
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int ans;
scanf("%d", &ans);
m[ans]++;
}
int num, sum = 0;
map<int, int>::iterator it = max_element(m.begin(), m.end(), cmp);
printf("%d %d\n", it -> first, it -> second);
}
return 0;
}
相关文章推荐
- java语言基础总结
- EF学习和使用(二)ModelFirst
- 轨道机动算法的C++实现
- Leetcode刷题总结
- 循环多少次?(1799)
- android开发之gridlayout使用入门
- android开发之gridlayout使用入门
- android开发之gridlayout使用入门
- android开发之gridlayout使用入门
- 象棋AI算法(一)
- hdoj1213 How many tables?(并查集)
- 设计模式之设计原则学习
- [UVA1595]Symmetry
- 【交换安全】DAI - Dynamic ARP Inspection 详解
- DEC6713开发板的摸索(1)
- JavaScript replaceall 方法
- 《现代操作系统》精读与思考笔记 第二章 进程和线程
- 进程管理(3-4)
- HDU 1074 Doing Homework(状压dp)
- 数据结构之---C语言实现图的十字链表存储表示