重复出现的数字
2015-06-16 15:08
330 查看
Input
输入有多组测试用例,对于每组测试用例:
输入一个整数N(N <= 106),随后输入N个整数Ni(0 < Ni <= 104)
Output
输出出现次数最多的数字和对应次数,如果出现次数最多的数有多个,输出数字最大的那个。
Sample Input
5
1 1 2 2 3
5
1 2 3 4 4
Sample Output
2 2
4 2
输入有多组测试用例,对于每组测试用例:
输入一个整数N(N <= 106),随后输入N个整数Ni(0 < Ni <= 104)
Output
输出出现次数最多的数字和对应次数,如果出现次数最多的数有多个,输出数字最大的那个。
Sample Input
5
1 1 2 2 3
5
1 2 3 4 4
Sample Output
2 2
4 2
[code]#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> using namespace std; int aa[1000006]; #define OPP int main() { int n, xx; #ifdef O1PP freopen("in.txt", "r", stdin); #endif // OPP while(~scanf("%d", &n)) { int t = 0; memset(aa, 0, sizeof(aa)); for(int i = 0; i < n; i++) { scanf("%d", &xx); t = max(t, xx); aa[xx]++; //下标标记 } int maxx = 0, k= 0; for(int i = 1; i <= t; i++) { if(maxx <= aa[i])//就是坑在这里了 { maxx = aa[i]; k = i; } } printf("%d %d\n", k, maxx); } return 0; }
相关文章推荐
- BeagleBone Black教训四局:简单LED对照实验
- SQL语句备忘
- JavaScript常用函数以及语法
- [Training Video - 5] [Groovy Script Test Step - Collections, Exceptions] HashSet and Hashtable
- SecureCRT experienced a fatal error and must close.A crash dump file has been created i
- PHP json_encode() 函数介绍
- springmvc数据验证
- ListView和HorizontalScrollView焦点冲突
- 使用jxl导入excel文件
- tomcat 详解
- JAVA将反斜杠"\"转成正斜杠"/"
- 并查集求最近公共祖先
- 指针与引用的一些见解与验证
- Java GUI程序设计的初步上
- [POJ_1125]Stockbroker Grapevine
- CSS(3)-样式来源与层叠规则
- 【ActionScript】组件的颜色变换
- UVALive 3027---Corporative Network+并查集的应用
- 人工智能搜索算法(深度优先、迭代加深、一致代价、A*搜索)
- ASIHTTPRequest缓存策略download cache