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