Problem Description
某校学生会主席由全校学生投票选举产生,共有m名候选人报名参选,编号为1到m(0<m<1000),全校有n名学生(0<n<30000),每人都可以投票。但每人只能投一票,每票只能选1名候选人。请你设计一个程序能够统计出哪个候选人得票最高,得了多少票。不会出现得票数相同的情况。
Input
第一行输入候选人数m和学生数n,以空格分开;
下面依次输入每个学生所选的候选人的编号。
下面依次输入每个学生所选的候选人的编号。
Output
第一行输出得票最多的候选人编号;
第二行输出该候选人所得的票数。
第二行输出该候选人所得的票数。
Example Input
3 10 1 2 3 2 3 1 2 3 1 3
Example Output
3 4
Hint
Author
01 | #include <iostream> |
02 | #include<stdio.h> |
03 | #include<string.h> |
04 | using namespace std; |
05 | int a[1001]; |
06 | int m,n; |
07 | int temp; |
08 |
09 | int main() |
10 | { |
11 |
12 | scanf ( "%d %d" ,&m,&n); |
13 |
14 | memset (a,0, sizeof (a)); |
15 | for ( int i=1; i<=n; i++) |
16 | { |
17 | cin>>temp; |
18 | a[temp]++; |
19 | } |
20 | int t,maxn=0; |
21 | for ( int j=1; j<=m; j++) |
22 | { |
23 | if (a[j]>maxn) |
24 | { |
25 | maxn=a[j]; |
26 | t=j; |
27 | } |
28 |
29 | } |
30 | printf ( "%d\n" ,t); |
31 | printf ( "%d" ,maxn); |
32 |
33 | return 0; |
34 | } |