There are two things that cats love most: 1) sleeping and 2) attending beauty contests. The most important thing for each female cat is the contest “Miss Cat”. There are always ten cats that participate in the final round of the contest, numbered 1 to 10.
The jury of the contest consists of N people who subjectively decide which cat to vote for. In other words each person votes for just 1 cat that he has most liked, or from whose owner he has received the biggest bribe. The winner of the contest is the cat that has gathered most votes. If two cats have equal votes, the winner of the contest is the one whose number is smaller.
Your task is to write a computer program that finds the number of the cat that is going to win the contest “Miss cat”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class MissCat { static void Main() { int sum1 = 0; int sum2 = 0; int sum3 = 0; int sum4 = 0; int sum5 = 0; int sum6 = 0; int sum7 = 0; int sum8 = 0; int sum9 = 0; int sum10 = 0; int N = int.Parse(Console.ReadLine()); List<int> listJury = new List<int>(); for (int i = 1; i <= N; i++) { int catNum = int.Parse(Console.ReadLine()); listJury.Add(catNum); if (catNum == 1) { sum1++; } else if (catNum == 2) { sum2++; } else if (catNum == 3) { sum3++; } else if (catNum == 4) { sum4++; } else if (catNum == 5) { sum5++; } else if (catNum == 6) { sum6++; } else if (catNum == 7) { sum7++; } else if (catNum == 8) { sum8++; } else if (catNum == 9) { sum9++; } else if (catNum == 10) { sum10++; } } List<int> listSum = new List<int>() { sum1, sum2, sum3, sum4, sum5, sum6, sum7, sum8, sum9, sum10 }; switch (listSum.IndexOf(listSum.Max())) { case 0: Console.WriteLine("1"); break; case 1: Console.WriteLine("2"); break; case 2: Console.WriteLine("3"); break; case 3: Console.WriteLine("4"); break; case 4: Console.WriteLine("5"); break; case 5: Console.WriteLine("6"); break; case 6: Console.WriteLine("7"); break; case 7: Console.WriteLine("8"); break; case 8: Console.WriteLine("9"); break; case 9: Console.WriteLine("10"); break; default: Console.WriteLine("error"); break; } } } |