Advertisement
Vickyyy01

Student Cables - my solution

Oct 30th, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using System;
  2.                    
  3. public class Program
  4. {
  5.     public static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.         int[] length = new int[n];
  9.         string[] unit = new string[n];
  10.        
  11.         for(int i = 0; i < n; i++)
  12.         {
  13.             length[i] = int.Parse(Console.ReadLine());
  14.             unit[i] = Console.ReadLine();
  15.         }
  16.        
  17.        
  18.         int[] result = new int[n];
  19.         for(int j = 0; j < n; j++)
  20.         {
  21.             if(unit[j] == "meters")
  22.             {
  23.                 result[j] = length[j] * 100;
  24.             }
  25.             else if(unit[j] == "centimeters")
  26.             {
  27.                 result[j] = length[j];
  28.             }
  29.         }
  30.        
  31.         int sum = 0;
  32.         int plus = 0;
  33.         for(int k = 0; k < n; k++)
  34.         {
  35.             if(result[k] >= 20)
  36.             {
  37.                 sum = sum + result[k];
  38.                 plus++;
  39.             }
  40.         }
  41.        
  42.         sum = sum - (3 * (plus - 1));
  43.         int SumCables = (int)(sum / 504);
  44.         int remaining = sum % 504;
  45.        
  46.         Console.WriteLine(SumCables);
  47.         Console.WriteLine(remaining);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement