Advertisement
dimipan80

Exam July Morning 1. Melons and Watermelons

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