15-07-08 Array-voting for squad leader

Source: Internet
Author: User
Tags ticket

A total of 20 students in each class, vote for the monitor, a total of 5 candidates, to achieve the vote, and calculate the most votes the person and his number of votes

int[] TP =New int[ -];//everybody vote.            int[] PS =New int[5];//the number of votes received by each person//vote             for(inti =0; I < TP. Length; i++) {Console.WriteLine ("Support number Please press 1, support second, press 2, support third, press 3, support fourth, press 4, support fifth please press 5"); Tp[i]=Convert.ToInt32 (Console.ReadLine ()); }                        //find out how many votes each candidate has received             for(intj =0; J < TP. Length; J + +)            {                if(Tp[j] = =1)//If you vote 1, the first student adds a ticket.{ps[0] = ps[0] +1; }                Else if(Tp[j] = =2)//vote 2 and the second student adds a ticket.{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; }            }            //See who has the most votes            intmax = ps[0];//find the biggest             for(intx =1; X < PS. Length; X + +)            {                if(Max <Ps[x]) {Max=Ps[x]; }            }            //OutputConsole.WriteLine ("the maximum number of votes received is:"+max); Console.Write ("the person with the highest number of votes:");  for(inty =0; Y < PS. Length; y++)            {                if(Ps[y] = =max) {Console.Write (y+1+","); }} console.readline ();

15-07-08 Array-voting for squad leader

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.