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 Task2
- {
- class Program
- {
- static void Main(string[] args)
- {
- string direction = Console.ReadLine();
- string input = Console.ReadLine();
- string exitDirection = string.Empty;
- int degrees = 0;
- while (!input.Equals("END"))
- {
- degrees += int.Parse(input);
- while (degrees >= 180)
- {
- degrees = degrees - 180;
- }
- while (degrees < 0)
- {
- degrees = 180 + degrees;
- }
- input = Console.ReadLine();
- }
- exitDirection = GetExitDirection(direction, degrees);
- string fullNameIn = GetDirectionWord(direction);
- string fullnameOut = GetDirectionWord(exitDirection);
- Console.WriteLine($"Starting Position: {fullNameIn}");
- Console.WriteLine($"Position After Rotating: {fullnameOut}");
- }
- private static string GetDirectionWord(string exitDirection)
- {
- if (exitDirection == "N")
- {
- exitDirection = "North";
- }
- else if (exitDirection == "S")
- {
- exitDirection = "South";
- }
- else if (exitDirection == "E")
- {
- exitDirection = "East";
- }
- else if (exitDirection == "W")
- {
- exitDirection = "West";
- }
- return exitDirection;
- }
- private static string GetExitDirection(string direction, int degrees)
- {
- string exit = string.Empty;
- if (direction == "N")
- {
- if (degrees == 45)
- {
- exit = "E";
- }
- else if (degrees == 90)
- {
- exit = "S";
- }
- else if (degrees == 135)
- {
- exit = "W";
- }
- else if (degrees == 0)
- {
- exit = "N";
- }
- }
- else if (direction == "E")
- {
- if (degrees == 45)
- {
- exit = "S";
- }
- else if (degrees == 90)
- {
- exit = "W";
- }
- else if (degrees == 135)
- {
- exit = "N";
- }
- else if (degrees == 0)
- {
- exit = "E";
- }
- }
- else if (direction == "S")
- {
- if (degrees == 45)
- {
- exit = "W";
- }
- else if (degrees == 90)
- {
- exit = "N";
- }
- else if (degrees == 135)
- {
- exit = "E";
- }
- else if (degrees == 0)
- {
- exit = "S";
- }
- }
- else if (direction == "W")
- {
- if (degrees == 45)
- {
- exit = "N";
- }
- else if (degrees == 90)
- {
- exit = "E";
- }
- else if (degrees == 135)
- {
- exit = "S";
- }
- else if (degrees == 0)
- {
- exit = "W";
- }
- }
- return exit;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement