psotirov

Miss Cat 2011

Dec 10th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2.  
  3. class MissCat
  4. {
  5.     static void Main()
  6.     {
  7.         int[] catVotes = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // initial votes per each of all 10 cats is 0
  8.  
  9.         int voters = int.Parse(Console.ReadLine()); // reads number of voters
  10.  
  11.         for (int i = 0; i < voters; i++) // Loop to enter votes
  12.         {
  13.             int vote = int.Parse(Console.ReadLine()); // obtains the vote
  14.             catVotes[vote-1]++; // assigns to respective cat
  15.         }
  16.  
  17.         int result = 0; // assumes that cat Nr.1 is the winner
  18.         for (int i = 1; i < 10; i++) // iterates through all other cats
  19.         {
  20.             if (catVotes[i] > catVotes[result]) result = i; // if i-th cat has greater vote than current she becomes a temporary winnner
  21.         }
  22.  
  23.         Console.WriteLine(result+1);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment