Advertisement
tanya_tsenkina

Untitled

May 27th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 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 Compass
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Char startPosition = char.Parse(Console.ReadLine());
  14. Char endPosition = 'N';
  15. //така са последователно
  16. char[] allDirection = new char[] { 'N', 'E', 'S', 'W' };
  17. //искам да ги подредя така, че старта да ми е на първо място
  18. char[] OrderDirection = ReorderDirection(startPosition, allDirection);
  19.  
  20. //Console.WriteLine(string.Join(" ", OrderDirection));
  21.  
  22. var input = Console.ReadLine();
  23. var sumDegees = 0;
  24. while (input != "END")
  25. {
  26. sumDegees += int.Parse(input);
  27. input = Console.ReadLine();
  28. }
  29.  
  30. //Ако имаме положително число
  31. if ((sumDegees <= 180) && (sumDegees >= 0))
  32. {
  33. endPosition = OrderDirection[(sumDegees / 45)%OrderDirection.Length];
  34. }else if (sumDegees > 180){
  35. sumDegees = sumDegees % 180;
  36. endPosition = OrderDirection[(sumDegees / 45) % OrderDirection.Length];
  37. }
  38. else if ((sumDegees >= -180) && (sumDegees <= 0))
  39. {
  40. endPosition = OrderDirection[OrderDirection.Length -Math.Abs((sumDegees / 45) % OrderDirection.Length)];
  41. } else if(sumDegees < -180){
  42. sumDegees = sumDegees % 180;
  43. endPosition = OrderDirection[OrderDirection.Length - Math.Abs((sumDegees / 45) % OrderDirection.Length)];
  44. }
  45.  
  46. Dictionary<char, string> AllWord = new Dictionary<char, string>();
  47. AllWord.Add('N', "North");
  48. AllWord.Add('E', "East");
  49. AllWord.Add('W', "West");
  50. AllWord.Add('S', "South");
  51.  
  52.  
  53. Console.WriteLine($"Starting Position: {AllWord[startPosition]}");
  54. Console.WriteLine($"Position After Rotating: {AllWord[endPosition]}");
  55. }
  56.  
  57. static char[] ReorderDirection(char position, char[] allDirection)
  58. {
  59. var index = 0;
  60. char[] output = new char[4];
  61. for (int i = 0; i < 4; i++)
  62. {
  63. if (allDirection[i] == position)
  64. {
  65. index = i;
  66. }
  67. }
  68. for (int i = 0; i < 4; i++)
  69. {
  70. output[i] = allDirection[(i + index) % 4];
  71. }
  72. return output;
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement