Advertisement
Spocoman

02. Car Race

Feb 4th, 2022
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CarRace
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<double> time = Console.ReadLine().Split().Select(double.Parse).ToList();
  12.  
  13.             while(time.Count != 3)
  14.             {
  15.                 double currentLeft = time[1];
  16.                 double currentRight = time[time.Count - 2];
  17.  
  18.                 time[1] += time[0];
  19.                 time[1] *= currentLeft == 0 ? 0.8 : 1;
  20.  
  21.                 time[time.Count - 2] += time[time.Count - 1];
  22.                 time[time.Count - 2] *= currentRight == 0 ? 0.8 : 1;
  23.  
  24.                 time.RemoveAt(0);
  25.                 time.RemoveAt(time.Count - 1);
  26.             }
  27.             string winner = time[0] < time[2] ? "left" : "right";
  28.             double total = time[0] < time[2] ? time[0] : time[2];
  29.  
  30.             Console.WriteLine($"The winner is {winner} with total time: {total}");
  31.         }
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement