Advertisement
AnetaKoseva

Car Race

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