Advertisement
skipter

C# Altitude

Jun 23rd, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace _17.Altitude
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] altitudeArray = Console.ReadLine().Split(' ').ToArray();
  11.  
  12.             long altitude = Convert.ToInt64(altitudeArray[0]);
  13.  
  14.             for (int cnt = 0; cnt < altitudeArray.Length; cnt++)
  15.             {
  16.                 if (altitudeArray[cnt] == "up")
  17.                 {
  18.                     altitude += Convert.ToInt64(altitudeArray[cnt + 1]);
  19.                 }
  20.                 if (altitudeArray[cnt] == "down")
  21.                 {
  22.                     altitude -= Convert.ToInt64(altitudeArray[cnt + 1]);
  23.                 }
  24.                 if (altitude <= 0)
  25.                 {
  26.                     Console.WriteLine("crashed");
  27.                     return;
  28.                 }
  29.             }
  30.             Console.WriteLine($"got through safely. current altitude: {altitude}m");
  31.            
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement