Advertisement
pavlinpetkov88

Altitude от Simple Arrays

Feb 14th, 2017
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace simpleArrays
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<string> input = Console.ReadLine().Split().ToList();
  13.             long altitude = long.Parse(input[0]);
  14.             List<string> commands = getCommands(input);
  15.  
  16.             for (int i = 0; i < commands.Count; i++)
  17.             {
  18.                 string[] comm = commands[i].Split();
  19.                 string upOrDown = comm[0];
  20.                 long Count = long.Parse(comm[1]);
  21.                 if (upOrDown.Equals("up"))
  22.                 {
  23.                     altitude += Count;
  24.                 }
  25.                 else
  26.                 {
  27.                     altitude -= Count;
  28.                 }
  29.  
  30.                 if (altitude <= 0)
  31.                 {
  32.                     Console.WriteLine("crashed");
  33.                     break;
  34.                 }
  35.             }
  36.  
  37.             if (altitude > 0)
  38.             {
  39.                 Console.WriteLine("got through safely. current altitude: {0}m",altitude);
  40.             }
  41.  
  42.         }
  43.  
  44.         private static List<string> getCommands(List<string> input)
  45.         {
  46.             List<string> a = new List<string>();
  47.             for (int i = 1; i < input.Count; i+=2)
  48.             {
  49.                 a.Add(input[i] + " " + input[i + 1]);
  50.             }
  51.             return a;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement