zoukankan      html  css  js  c++  java
  • 投票选班长

    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();
            }
  • 相关阅读:
    10 vue中 v-model ,计算机demo
    linear-gradient
    flexible.js
    九宫格抽奖原理
    js匿名函数与闭包作用
    HTML5实现九宫格布局
    scrollLeft/scrollTop/scrollHeight
    通过media媒体查询设置ie7/8样式、使用media判断各机型、手淘flexible.js
    右击事件oncontentmenu
    js/jquery判断一个对象是否为空
  • 原文地址:https://www.cnblogs.com/SJP666/p/4646673.html
Copyright © 2011-2022 走看看