Advertisement
Guest User

02. Car Race

a guest
Feb 18th, 2020
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Car_Race
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> time = Console.ReadLine()
  12.                 .Split()
  13.                 .Select(int.Parse)
  14.                 .ToList();
  15.             decimal sumLeft = 0.0m;
  16.             decimal sumRight = 0.0m;
  17.  
  18.             for (int i = 0; i < time.Count / 2; i++)
  19.             {
  20.                 if (time[i] == 0)
  21.                 {
  22.                     sumLeft *= 0.8m;
  23.                 }
  24.                 else
  25.                 {
  26.                     sumLeft += time[i];
  27.                 }
  28.  
  29.                 if (time[time.Count - i - 1] == 0)
  30.                 {
  31.                     sumRight *= 0.8m;
  32.                 }
  33.                 else
  34.                 {
  35.                     sumRight += time[time.Count - i - 1];
  36.                 }
  37.             }
  38.  
  39.             if (sumLeft <= sumRight)
  40.             {
  41.                 Console.WriteLine($"The winner is left with total time: {sumLeft:F1}");
  42.             }
  43.             else
  44.             {
  45.                 Console.WriteLine($"The winner is right with total time: {sumRight:F1}");
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement