Advertisement
VyaraG

StudentCables

Dec 10th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1. //Nakov, the main driver of SoftUni, decided to solve the problem by connecting some of the students through a standard network cables. He installed a few network switches in the exam lab and started to prepare cables for the students. His idea was to use 5 meters long cables (called student cables) between the switches and the student's laptops. Nakov wanted to create as much as possible cables of size 5 meters. He had a lot of cables of different sizes, e.g. a big roll of 300 meters, another big roll of 130 meters and a few small cables of 30 cm, 15 cm and 10 cm. The cables had different sizes and was measured in different measures (meters or centimeters). Nakov calculated that he needed 2 cm for crimping each RJ45 connector and 3 cm for joining each two pieces of cable. It was complex to calculate how much cables Nakov can create so he needs your help.
  2. //Write a program that takes as an input a sequence of N cables of different sizes and calculates how many student cables Nakov can create by first joining them all together, then cut them into 5 meters and 4 cm, and finally crimp the RJ45 connectors to obtain 5 meters long student network cables. Calculate also the length of the unused remaining cable. Note that cables shorter than 20 cm in the input will be thrown away, so please discard therm.
  3. //Input
  4. //The input data should be read from the console.
  5. //•   At the first line an integer number n specifying the number of cables will be given.
  6. //•   At the next 2 * n lines the cables will be given: first comes the cable length; second comes the measure.
  7. //The input data will always be valid and in the format described. There is no need to check it explicitly.
  8. //Output
  9. //The output should be printed on the console. It should consist of exactly 2 lines:
  10. //•   The first line should hold the number of student cables.
  11. //•   The second line should hold the length of the remaining cable.
  12. //Constraints
  13. //•   The number n will be integer in the range [1 … 100].
  14. //•   The cable length is integer in the range [1 … 500].
  15. //•   The cable measure is one of the following values: meters, centimeters.
  16. //•   Allowed working time for your program: 0.1 seconds. Allowed memory: 16 MB.
  17.  
  18.  
  19. using System;
  20.  
  21. class StudentCables
  22. {
  23.     static void Main()
  24.     {
  25.         int numberOfCables = int.Parse(Console.ReadLine());
  26.         int totalLegth = 0;
  27.         int countCables = 0;
  28.  
  29.         for (int i = 0; i < numberOfCables; i++)
  30.         {
  31.             int legth = int.Parse(Console.ReadLine());
  32.             string measure = Console.ReadLine();
  33.  
  34.             //Meters to centimeters
  35.  
  36.             if (measure=="meters")
  37.             {
  38.                 legth *= 100;
  39.  
  40.             }
  41.             if (legth>=20)
  42.             {
  43.                 totalLegth += legth;
  44.                 countCables++;
  45.             }
  46.         }
  47.         totalLegth -= 3*(countCables - 1); //sutract the joins
  48.         Console.WriteLine(totalLegth/504);
  49.         Console.WriteLine(totalLegth%504); //remainder
  50.     }  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement