Advertisement
Filkolev

Melons And Watermelons - optimized

Jul 26th, 2014
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2.  
  3. class MelonsAndWatermelons
  4. {
  5.     static void Main()
  6.     {
  7.         int startingDay = int.Parse(Console.ReadLine());
  8.         int numberOfDays = int.Parse(Console.ReadLine());
  9.  
  10.         int countOfMelons = 0;
  11.         int countOfWatermelons = 0;
  12.  
  13.         int fullWeeks = numberOfDays / 7;
  14.  
  15.         countOfMelons += fullWeeks * 7;
  16.         countOfWatermelons += fullWeeks * 7;
  17.  
  18.         int remainingDays = numberOfDays % 7;
  19.  
  20.         for (int currentDay = startingDay; currentDay < startingDay + remainingDays; currentDay++)
  21.         {
  22.             int dayOfWeek = currentDay % 7;
  23.  
  24.             switch (dayOfWeek)
  25.             {
  26.                 case 1:
  27.                     countOfWatermelons++;
  28.                     break;
  29.                 case 2:
  30.                     countOfMelons += 2;
  31.                     break;
  32.                 case 3:
  33.                     countOfMelons++;
  34.                     countOfWatermelons++;
  35.                     break;
  36.                 case 4:
  37.                     countOfWatermelons += 2;
  38.                     break;
  39.                 case 5:
  40.                     countOfMelons += 2;
  41.                     countOfWatermelons += 2;
  42.                     break;
  43.                 case 6:
  44.                     countOfWatermelons++;
  45.                     countOfMelons += 2;
  46.                     break;
  47.             }
  48.         }
  49.  
  50.  
  51.         if (countOfMelons == countOfWatermelons)
  52.         {
  53.             Console.WriteLine("Equal amount: {0}", countOfMelons);
  54.         }
  55.  
  56.         else if (countOfMelons > countOfWatermelons)
  57.         {
  58.             Console.WriteLine("{0} more melons", countOfMelons - countOfWatermelons);
  59.         }
  60.  
  61.         else
  62.         {
  63.             Console.WriteLine("{0} more watermelons", countOfWatermelons - countOfMelons);
  64.         }
  65.  
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement