选票统计
来源:互联网 发布:淘宝溢价是什么意思 编辑:程序博客网 时间:2024/05/16 05:00
选票统计
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
某校学生会主席由全校学生投票选举产生,共有m名候选人报名参选,编号为1到m(0<m<1000),全校有n名学生(0<n<30000),每人都可以投票。但每人只能投一票,每票只能选1名候选人。请你设计一个程序能够统计出哪个候选人得票最高,得了多少票。不会出现得票数相同的情况。
Input
第一行输入候选人数m和学生数n,以空格分开;
下面依次输入每个学生所选的候选人的编号。
下面依次输入每个学生所选的候选人的编号。
Output
第一行输出得票最多的候选人编号;
第二行输出该候选人所得的票数。
第二行输出该候选人所得的票数。
Example Input
3 101 2 3 2 3 1 2 3 1 3
Example Output
34
#include <bits/stdc++.h>using namespace std;const int M=1005;int m,n,tmp;struct candidate{int number;int ticket;}candi[M];bool cmp(const candidate& x,const candidate& y){return x.ticket>y.ticket;//这里不能写成:return x.ticket>=y.ticket }int main(){cin>>m>>n;for(int i=1;i<=m;i++){candi[i].number=i;candi[i].ticket=0;}for(int i=1;i<=n;i++){cin>>tmp;candi[tmp].ticket++;}sort(candi+1,candi+1+m,cmp);cout<<candi[1].number<<endl;cout<<candi[1].ticket<<endl;return 0;}
0 0
- 统计选票
- 统计选票
- 选票统计
- 选票统计
- 选票统计
- 选票统计
- 选票统计
- 选票统计
- 选票统计
- 选票统计
- 选票统计
- 选票统计
- 选票统计
- 1294选票统计
- 选票统计系统
- SDUTOJ 1294选票统计
- sdut1294选票统计
- 选票统计 (sdut oj)
- 00、node介绍
- The specified child already has a parent. You must call removeView() on the child's parent first问题
- ifstream读取文件和stringstream读取内容
- 树的存储结构
- hdu1242 Rescue BFS+优先队列
- 选票统计
- Java的安全初始化
- python 调用 有道api接口
- leecode 解题总结:342. Power of Four
- 为什么(i++)不能做左值,而(++i)可以
- ACM-最难的问题(字符串处理)
- 【L3_002】堆栈【线段树】
- php函数microtime
- JasperReport6.3.1官网下载