Advertisement
bepcho

Compass

May 27th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.91 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 Task2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string direction = Console.ReadLine();
  14.             string input = Console.ReadLine();
  15.             string exitDirection = string.Empty;
  16.             int degrees = 0;
  17.             while (!input.Equals("END"))
  18.             {
  19.                 degrees += int.Parse(input);
  20.                 while (degrees >= 180)
  21.                 {
  22.                     degrees = degrees - 180;
  23.                 }
  24.                 while (degrees < 0)
  25.                 {
  26.                     degrees = 180 + degrees;
  27.                 }
  28.  
  29.                 input = Console.ReadLine();
  30.             }
  31.  
  32.             exitDirection = GetExitDirection(direction, degrees);
  33.  
  34.             string fullNameIn = GetDirectionWord(direction);
  35.             string fullnameOut = GetDirectionWord(exitDirection);
  36.  
  37.             Console.WriteLine($"Starting Position: {fullNameIn}");
  38.             Console.WriteLine($"Position After Rotating: {fullnameOut}");
  39.  
  40.  
  41.         }
  42.  
  43.         private static string GetDirectionWord(string exitDirection)
  44.         {
  45.            
  46.             if (exitDirection == "N")
  47.             {
  48.                 exitDirection = "North";
  49.             }
  50.             else if (exitDirection == "S")
  51.             {
  52.                 exitDirection = "South";
  53.             }
  54.             else if (exitDirection == "E")
  55.             {
  56.                 exitDirection = "East";
  57.             }
  58.             else if (exitDirection == "W")
  59.             {
  60.                 exitDirection = "West";
  61.             }
  62.             return exitDirection;
  63.         }
  64.  
  65.         private static string GetExitDirection(string direction, int degrees)
  66.         {
  67.             string exit = string.Empty;
  68.  
  69.             if (direction == "N")
  70.             {
  71.                 if (degrees == 45)
  72.                 {
  73.                     exit = "E";
  74.                 }
  75.                 else if (degrees == 90)
  76.                 {
  77.                     exit = "S";
  78.                 }
  79.                 else if (degrees == 135)
  80.                 {
  81.                     exit = "W";
  82.                 }
  83.                 else if (degrees == 0)
  84.                 {
  85.                     exit = "N";
  86.                 }
  87.             }
  88.             else if (direction == "E")
  89.             {
  90.                 if (degrees == 45)
  91.                 {
  92.                     exit = "S";
  93.                 }
  94.                 else if (degrees == 90)
  95.                 {
  96.                     exit = "W";
  97.                 }
  98.                 else if (degrees == 135)
  99.                 {
  100.                     exit = "N";
  101.                 }
  102.                 else if (degrees == 0)
  103.                 {
  104.                     exit = "E";
  105.                 }
  106.             }
  107.             else if (direction == "S")
  108.             {
  109.                 if (degrees == 45)
  110.                 {
  111.                     exit = "W";
  112.                 }
  113.                 else if (degrees == 90)
  114.                 {
  115.                     exit = "N";
  116.                 }
  117.                 else if (degrees == 135)
  118.                 {
  119.                     exit = "E";
  120.                 }
  121.                 else if (degrees == 0)
  122.                 {
  123.                     exit = "S";
  124.                 }
  125.             }
  126.             else if (direction == "W")
  127.             {
  128.                 if (degrees == 45)
  129.                 {
  130.                     exit = "N";
  131.                 }
  132.                 else if (degrees == 90)
  133.                 {
  134.                     exit = "E";
  135.                 }
  136.                 else if (degrees == 135)
  137.                 {
  138.                     exit = "S";
  139.                 }
  140.                 else if (degrees == 0)
  141.                 {
  142.                     exit = "W";
  143.                 }
  144.             }
  145.  
  146.             return exit;
  147.  
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement