Advertisement
BorisSimeonov

Odd or Even Counter

Nov 11th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         int setCount = int.Parse(Console.ReadLine());
  8.         int numCount = int.Parse(Console.ReadLine());
  9.         string numType = Console.ReadLine();
  10.         int highestCount = 0;
  11.         int highestSet = 0;
  12.         string setName = "";
  13.  
  14.         for (int set = 0; set < setCount; set++)
  15.         {
  16.             int countBuffer = 0;
  17.             for (int num = 0; num < numCount; num++)
  18.             {
  19.                 int numberBuffer = int.Parse(Console.ReadLine());
  20.                 if (numType == "odd" && numberBuffer % 2 != 0)
  21.                 {
  22.                     countBuffer++;
  23.                 }
  24.                 else if (numType == "even" && numberBuffer % 2 == 0)
  25.                 {
  26.                     countBuffer++;
  27.                 }
  28.             }
  29.  
  30.             if (countBuffer > highestCount)
  31.             {
  32.                 highestCount = countBuffer;
  33.                 highestSet = set;
  34.             }
  35.         }
  36.         //visualization
  37.         setName = getSetName(highestSet);
  38.         if (highestCount != 0)
  39.         {
  40.             Console.WriteLine("{0} set has the most {1} numbers: {2}", setName, numType, highestCount);
  41.         }
  42.         else
  43.         {
  44.             Console.WriteLine("No");
  45.         }
  46.  
  47.     }
  48.  
  49.     private static string getSetName(int highestSet)
  50.     {
  51.         string x = "";
  52.         switch (highestSet)
  53.         {
  54.             case 0: x = "First";
  55.                 break;
  56.             case 1: x = "Second";
  57.                 break;
  58.             case 2: x = "Third";
  59.                 break;
  60.             case 3: x = "Fourth";
  61.                 break;
  62.             case 4: x = "Fifth";
  63.                 break;
  64.             case 5: x = "Sixth";
  65.                 break;
  66.             case 6: x = "Seventh";
  67.                 break;
  68.             case 7: x = "Eighth";
  69.                 break;
  70.             case 8: x = "Ninth";
  71.                 break;
  72.             case 9: x = "Tenth";
  73.                 break;
  74.         }
  75.         return x;
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement