Advertisement
Guest User

Untitled

a guest
Feb 16th, 2023
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | Source Code | 0 0
  1.  
  2. int[] points = Console.ReadLine()
  3.     .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  4.     .Select(int.Parse).ToArray();
  5.  
  6. int finIx = (points.Length / 2) + 1;
  7. double timeL = 0, timeR = 0;
  8.  
  9. for (int i = 0; i < finIx - 1; i++) //left car
  10. {
  11.     if (points[i] == 0)
  12.     {
  13.         timeL *= 0.8;
  14.     }
  15.     else
  16.     {
  17.         timeL += points[i];
  18.     }
  19.  
  20. }
  21. for (int i = points.Length - 1; i >= finIx; i--) //right car
  22. {
  23.     if (points[i] == 0)
  24.     {
  25.         timeR *= 0.8;
  26.     }
  27.     else
  28.  
  29.     {
  30.         timeR += points[i];
  31.     }
  32. }
  33. string winner;
  34. double time = 0;
  35. if (timeL > timeR)
  36. {
  37.     winner = "right";
  38.     time = timeR;
  39. }
  40. else
  41. {
  42.     winner = "left";
  43.     time = timeL;
  44. }
  45. Console.WriteLine($"The winner is {winner} with total time: {time:#.#}");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement