Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Altitude
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] inputArray = Console.ReadLine().Split(' ');
- string[] commands = new string[(inputArray.Length - 1) / 2];
- int tempCount = 1;
- for (int i = 0; i < commands.Length; i++)
- {
- commands[i] = inputArray[tempCount];
- tempCount += 2;
- }
- tempCount = 2;
- string[] height = new string[commands.Length];
- for (int i = 0; i < commands.Length; i++)
- {
- height[i] = inputArray[tempCount];
- tempCount += 2;
- }
- double altitude = double.Parse(inputArray[0]);
- for (int i = 0; i < commands.Length; i++)
- {
- if (commands[i] == "up")
- {
- altitude += double.Parse(height[i]);
- }
- else if (commands[i] == "down")
- {
- altitude -= double.Parse(height[i]);
- }
- if (altitude <= 0)
- {
- Console.WriteLine("crashed");
- break;
- }
- }
- if (altitude > 0)
- {
- Console.WriteLine($"got through safely. current altitude: {altitude}m");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement