Advertisement
Filkolev

StudentCables - corrected

Aug 25th, 2014
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. class StudentCables
  5. {
  6.     static void Main()
  7.     {
  8.         int cables = int.Parse(Console.ReadLine());
  9.    
  10.     // all variables can be int
  11.         int sumOfCables = 0;
  12.  
  13.         // stores how many cables we actually use after losing the short ones
  14.         int used = cables;
  15.  
  16.         for (int i = 0; i < cables; i++)
  17.         {
  18.             int cableLength = int.Parse(Console.ReadLine());
  19.             string measure = Console.ReadLine();
  20.             if (measure == "meters")
  21.             {
  22.                 cableLength = cableLength * 100;
  23.             }
  24.  
  25.             if (cableLength < 20 && measure != "meters")
  26.             {
  27.                 cableLength = 0;
  28.                 used--;
  29.             }            
  30.          
  31.           sumOfCables = sumOfCables + cableLength;            
  32.         }
  33.  
  34.     // the amount we cut depends on the number of cables actually used
  35.         sumOfCables = sumOfCables - (used - 1) * 3;
  36.  
  37.         int countCables = sumOfCables / 504;
  38.         int remainder = sumOfCables % 504; // simpler way to get the remainder
  39.        
  40.         Console.WriteLine(countCables);
  41.         Console.WriteLine(remainder);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement