Advertisement
YavorGrancharov

Altitude(80%)

Aug 7th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Altitude
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = Console.ReadLine();
  10.  
  11.             string[] tokens = input.Split(' ');
  12.             int alt = int.Parse(tokens[0]);
  13.  
  14.             for (int i = 1; i < tokens.Length; i++)
  15.             {
  16.                 if (tokens[i] == "up")
  17.                 {
  18.                     alt += int.Parse(tokens[i + 1]);
  19.                 }
  20.                 else if (tokens[i] == "down")
  21.                 {
  22.                     alt -= int.Parse(tokens[i + 1]);
  23.  
  24.                     if (alt <= 0)
  25.                     {
  26.                         break;
  27.                     }
  28.                 }
  29.             }
  30.  
  31.             if (alt > 0)
  32.             {
  33.                 Console.WriteLine("got through safely. current altitude: {0}m", alt);
  34.             }
  35.             else
  36.             {
  37.                 Console.WriteLine("crashed");
  38.             }            
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement