投票选班长
2015-07-14 21:40
549 查看
static void Main46投票选班长(string[] args) { ////某班有20个学生,投票选班长,总共有5个候选人,实现投票,并且计算出得票最多的人以及他的票数。 int[] tp = new int[20]; //每个人投的票 int[] ps = new int[5]; //每个候选人所得票数 for (int i = 0; i < tp.Length; i++) { Console.WriteLine("请投票,1代表第一个候选人,2代表第二个候选人--5带表第五个候选人"); tp[i] = Convert.ToInt32(Console.ReadLine()); } for (int j = 0; j < tp.Length; j++) { if (tp[j] == 1) { ps[0] = ps[0] + 1; } else if (tp[j] == 2) { ps[1] = ps[1] + 1; } else if (tp[j] == 3) { ps[2] = ps[2] + 1; } else if (tp[j] == 4) { ps[3] = ps[3] + 1; } else if (tp[j] == 5) { ps[4] = ps[4] + 1; } } //看一下谁得的票数最多 int max = ps[0]; //找出最大的 for (int x = 1; x < ps.Length; x++) { if (max < ps[x]) { max = ps[x]; } } //找最大的索引 int[] sy = new int[5]; for (int y = 0; y < ps.Length; y++) { if (ps[y] == max) { sy[y] = y + 1; } } //输出 Console.WriteLine("所得票数最多为:" + max); Console.WriteLine("所得票数最多的人为:"); for (int z = 0; z < sy.Length; z++) { if (sy[z] == 0) { } else { Console.WriteLine(sy[z]); } } Console.ReadLine(); }
相关文章推荐
- 234-e-Palindrome Linked List
- windows下安装redis
- Windows OS 下我做为开发人员常用的一些软件
- MySQL导入.sql文件及常用命令
- myeclipse创建user library
- WebService详解
- QQ输入密码的时候 键盘自动输入 (系统为win8)
- mybatis中>=和<=的实现方式
- 第三章、Linux根文件系统及文件管理命令详解
- Spark-1.4.0集群搭建
- POJ 3694 tarjan 桥+lca
- 【Essential c++】——(三)泛型编程风格
- 11G新特性 -- RMAN Multisection Backups
- boost库下载地址
- ueditor引入通用优酷视频
- windows上的自动备份工具
- win8快捷键
- 轻量级数据库sqlite的编译
- U盘安装CentOS无法进入Centos系统解决办法
- 乐视酷派造生态,后期执行是关键