Vote for the squad leader

Source: Internet
Author: User

Static voidMain46 voted for the squad leader (string[] args) {            ////There are 20 students in a class, voting for the monitor, a total of 5 candidates, to achieve the vote, and calculate the most votes and his number of votes.             int[] TP =New int[ -];//everybody vote.            int[] PS =New int[5];//The number of votes received by each candidate             for(inti =0; I < TP. Length; i++) {Console.WriteLine ("please vote, 1 for the first candidate, 2 for the second candidate,--5 with table fifth candidate"); Tp[i]=Convert.ToInt32 (Console.ReadLine ()); }             for(intj =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; }            }            //Look who's got the most votes.            intmax = ps[0];//find the biggest             for(intx =1; X < PS. Length; X + +)            {                if(Max <Ps[x]) {Max=Ps[x]; }            }            //find the largest index            int[] sy =New int[5];  for(inty =0; Y < PS. Length; y++)            {                if(Ps[y] = =max) {Sy[y]= y +1; }            }            //OutputConsole.WriteLine ("the maximum number of votes received is:"+max); Console.WriteLine ("the person with the highest number of votes:");  for(intz =0; Z < sy. Length; z++)            {                if(Sy[z] = =0)                {                }                Else{Console.WriteLine (sy[z]);        }} console.readline (); }

Vote for the 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.