Advertisement
akkirilov

Untitled

Feb 22nd, 2017
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication3
  8. {
  9. public class Racer
  10. {
  11. public string Name { get; set; }
  12. public double Fuel { get; set; }
  13. public long finished = -1;
  14. public Racer(string name, double fuel)
  15. {
  16. this.Name = name;
  17. this.Fuel = fuel;
  18.  
  19. }
  20. }
  21.  
  22. class Program
  23. {
  24. static void Main()
  25. {
  26. var participants = Console.ReadLine()
  27. .Split(new char[] { ' ' },
  28. StringSplitOptions.RemoveEmptyEntries);
  29.  
  30. var racers = new List<Racer>();
  31.  
  32. foreach (var part in participants)
  33. {
  34.  
  35. racers.Add(new Racer(part, part[0]));
  36.  
  37.  
  38. }
  39.  
  40. var track = Console.ReadLine()
  41. .Split(new char[] { ' ' },
  42. StringSplitOptions.RemoveEmptyEntries).Select(double.Parse)
  43. .ToList();
  44.  
  45. var checkPionts = Console.ReadLine()
  46. .Split(new char[] { ' ' },
  47. StringSplitOptions.RemoveEmptyEntries)
  48. .Select(int.Parse)
  49. .ToList();
  50.  
  51.  
  52.  
  53. for (int i = 0; i < track.Count; i++)
  54. {
  55. for (int j = 0; j < racers.Count; j++)
  56. {
  57. if (racers[j].Fuel <= 0)
  58. {
  59. continue;
  60. }
  61.  
  62. if (checkPionts.Any(ch => ch == i))
  63. {
  64. racers[j].Fuel += track[i];
  65. }
  66. else
  67. {
  68. racers[j].Fuel -= track[i];
  69. if (racers[j].Fuel <= 0)
  70. {
  71. racers[j].finished = i;
  72. }
  73. }
  74.  
  75. }
  76. }
  77. foreach (var item in racers)
  78. {
  79. if (item.finished !=-1)
  80. {
  81. Console.WriteLine($"{item.Name} - reached {item.finished}");
  82. }
  83. else Console.WriteLine("{0} - fuel left {1:f2}", item.Name, item.Fuel);
  84. }
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement