Advertisement
Aborigenius

*Altitude

Jun 17th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.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 Altitude
  8.  
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] doItPilot = Console.ReadLine().Split(' ').ToArray();
  15.             double altitude = double.Parse(doItPilot[0]);
  16.  
  17.             for (int i = 0; i < doItPilot.Length; i++)
  18.             {
  19.                 if (i % 2 != 0 && doItPilot[i] == "up")
  20.                 {
  21.                     altitude += double.Parse(doItPilot[i + 1]);
  22.                 }
  23.                 else if (i % 2 != 0 && doItPilot[i] == "down")
  24.                 {
  25.                     altitude -= double.Parse(doItPilot[i + 1]);
  26.  
  27.                     if (altitude < 0)
  28.                     {
  29.                         break;
  30.                     }
  31.                 }
  32.             }
  33.             if (altitude <= 0)
  34.             {
  35.                 Console.WriteLine("crashed");
  36.             }
  37.             else
  38.             {
  39.                 Console.WriteLine($"got through safely.current altitude: {altitude}");
  40.             }
  41.  
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement