Advertisement
Vladimir76

Endurance Rally

Feb 21st, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 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 Endurance_Rally
  8. {
  9.     class Participant
  10.     {
  11.         public string Name { get; set; }
  12.         public string Position { get; set; }
  13.         public double ValuePosition { get; set; }
  14.     }
  15.  
  16.     class Program
  17.     {
  18.         static void Main()
  19.         {
  20.             string[] name = Console.ReadLine()
  21.                 .Split(new char[] { ' '},
  22.                         StringSplitOptions.RemoveEmptyEntries);
  23.             double[] zones = Console.ReadLine()
  24.                 .Trim()
  25.                 .Split(new char[] { ' '},
  26.                         StringSplitOptions.RemoveEmptyEntries)
  27.                 .Select(double.Parse)
  28.                 .ToArray();
  29.             int[] checkPoint = Console.ReadLine()
  30.                 .Trim()
  31.                 .Split(new char[] { ' '},
  32.                         StringSplitOptions.RemoveEmptyEntries)
  33.                 .Select(int.Parse)
  34.                 .ToArray();
  35.  
  36.             List<Participant> participants = new List<Participant>();
  37.             bool check = false;
  38.             double[] fuel = new double[name.Length];
  39.  
  40.             for (int i = 0; i < name.Length; i++)
  41.             {
  42.                 int codeName = name[i][0];
  43.                 fuel[i] = codeName;
  44.             }
  45.  
  46.  
  47.             for (int i = 0; i < zones.Length; i++)
  48.             {
  49.                 zones[i] *= -1.0;
  50.             }
  51.  
  52.             for (int i = 0; i < checkPoint.Length; i++)
  53.             {
  54.                 if (checkPoint[i] >= 0 && checkPoint[i] < zones.Length)
  55.                 {
  56.                     zones[checkPoint[i]] *= -1.0;
  57.                 }                
  58.             }
  59.  
  60.             for (int i = 0; i < fuel.Length; i++)
  61.             {
  62.                 Participant person = new Participant();
  63.  
  64.                 for (int j = 0; j < zones.Length; j++)
  65.                 {
  66.                     fuel[i] += zones[j];
  67.                     if ((fuel[i]<=0))
  68.                     {
  69.                         person.Name = name[i];
  70.                         person.Position = "reached";
  71.                         person.ValuePosition = (double)j;
  72.                         participants.Add(person);
  73.                         check = true;
  74.                         break;
  75.                     }
  76.                 }
  77.                 if (!check)
  78.                 {
  79.                     person.Name = name[i];
  80.                     person.Position = "fuel left";
  81.                     person.ValuePosition = fuel[i];
  82.                     participants.Add(person);
  83.                    
  84.                 }
  85.                 check = false;
  86.             }
  87.             foreach (var result in participants)
  88.             {
  89.                 Console.Write("{0} - {1} ",
  90.                     result.Name,result.Position);
  91.                 if (result.Position== "reached")
  92.                 {
  93.                     Console.WriteLine("{0}",result.ValuePosition);
  94.                 }
  95.                 else
  96.                 {
  97.                     Console.WriteLine("{0:F2}",result.ValuePosition);
  98.                 }
  99.             }
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement