Advertisement
SecretWorker

Taninim

Nov 11th, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. static void Main(string[] args)
  2.         {
  3.             int[] years = new int[2016];
  4.             Console.WriteLine("How many taninim?");
  5.             int n = int.Parse(Console.ReadLine());
  6.             Console.WriteLine("K! Great job");
  7.             for (int i = 0; i < n; i++)
  8.             {
  9.                 Console.WriteLine("Tanin no." + (i + 1) + ":");
  10.                 Console.Write("Shnat Lida:");
  11.                 int bYear = int.Parse(Console.ReadLine());
  12.                 Console.Write("Shnat Ptira:");
  13.                 int dYear = int.Parse(Console.ReadLine());
  14.                 years = AddYears(bYear, dYear, years);
  15.                 Console.WriteLine("---------------");
  16.             }
  17.             int[] motek = checkMax(years);
  18.             Console.WriteLine("YEAR: " + motek[0] + ", TANINIM: " + motek[1]);
  19.         }
  20.         static int[] checkMax(int[] years)
  21.         {
  22.             int max = 0;
  23.             int ftrI = 0;
  24.             int ftrTimes = 0;
  25.             for (int i = 0; i < years.Length; i++)
  26.             {
  27.                 if (years[i] > max)
  28.                 {
  29.                     max = years[i];
  30.                     ftrI = i;
  31.                     ftrTimes = years[i];
  32.                 }
  33.             }
  34.             int[] returning = new int[2];
  35.             returning[0] = ftrI;
  36.             returning[1] = ftrTimes;
  37.             return returning;
  38.              
  39.         }
  40.         static int[] AddYears(int b, int d, int[] years)
  41.         {
  42.             for (int i = b; i <= d; i++)
  43.             {
  44.                 years[i]++;
  45.             }
  46.             return years;
  47.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement