Advertisement
gospod1978

List-Ex/More/Car Race

Oct 23rd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace fundamental14
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<int> timeCar = Console.ReadLine().
  12.                 Split().
  13.                 Select(int.Parse).
  14.                 ToList();
  15.             double timeRightCar = 0;
  16.             double timeLeftCar = 0;
  17.  
  18.             WinnerCar(timeCar, timeRightCar,  timeLeftCar);
  19.  
  20.         }
  21.  
  22.         private static void WinnerCar(List<int> timeCar, double timeRightCar, double timeLeftCar)
  23.         {
  24.             timeLeftCar = LeftCar(timeCar, timeLeftCar);
  25.  
  26.             timeRightCar = RightCar(timeCar, timeRightCar);
  27.  
  28.             if (timeLeftCar < timeRightCar)
  29.             {
  30.                 Console.WriteLine($"The winner is left with total time: {timeLeftCar}");
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine($"The winner is right with total time: {timeRightCar}");
  35.             }
  36.         }
  37.  
  38.         private static double RightCar(List<int> timeCar, double timeRightCar)
  39.         {
  40.             for (int i = timeCar.Count - 1; i > timeCar.Count / 2; i--)
  41.             {
  42.                 if (timeCar[i] == 0)
  43.                 {
  44.                     timeRightCar *= 0.8;
  45.                 }
  46.                 else
  47.                 {
  48.                     timeRightCar += timeCar[i];
  49.                 }
  50.             }
  51.  
  52.             return timeRightCar;
  53.         }
  54.  
  55.         private static double LeftCar(List<int> timeCar, double timeLeftCar)
  56.         {
  57.             for (int i = 0; i < timeCar.Count / 2; i++)
  58.             {
  59.                 if (timeCar[i] == 0)
  60.                 {
  61.                     timeLeftCar *= 0.8;
  62.                 }
  63.                 else
  64.                 {
  65.                     timeLeftCar += timeCar[i];
  66.                 }
  67.             }
  68.            
  69.             return timeLeftCar;
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement