Advertisement
grubcho

Altitude

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