Advertisement
bullit3189

Car Race - Lists

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