Advertisement
alidzhikov

ToTheStars

May 8th, 2015
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class ToTheStars
  5. {
  6.     static void Main()
  7.     {
  8.         Dictionary<string, Tuple<double, double>> starSystemsDictionary = new Dictionary<string, Tuple<double, double>>();
  9.  
  10.         string startSystemName = String.Empty;
  11.         double starSystemCoordinateX = 0;
  12.         double starSystemCoordinateY = 0;
  13.         string[] starSystemsTokens;
  14.         for (int i = 0; i < 3; i++)
  15.         {
  16.             starSystemsTokens = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  17.             startSystemName = starSystemsTokens[0];
  18.             starSystemCoordinateX = double.Parse(starSystemsTokens[1]);
  19.             starSystemCoordinateY = double.Parse(starSystemsTokens[2]);
  20.  
  21.             starSystemsDictionary[startSystemName] = new Tuple<double, double>(starSystemCoordinateX, starSystemCoordinateY);
  22.         }
  23.  
  24.         string[] spaceshipStartCordinates = Console.ReadLine()
  25.             .Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  26.         int numberOfMoves = int.Parse(Console.ReadLine());
  27.         double spaceshipX = double.Parse(spaceshipStartCordinates[0]);
  28.         double spaceshipY = double.Parse(spaceshipStartCordinates[1]);
  29.  
  30.         bool isInStarSystem = false;
  31.         while (numberOfMoves >= 0)
  32.         {
  33.             isInStarSystem = false;
  34.             foreach (var pair in starSystemsDictionary)
  35.             {
  36.                 if (IsInStarSystem(pair.Value.Item1, pair.Value.Item2, spaceshipX, spaceshipY))
  37.                 {
  38.                     Console.WriteLine(pair.Key.ToLower());
  39.                     isInStarSystem = true;
  40.                     break;
  41.                 }
  42.             }
  43.  
  44.             if (!isInStarSystem)
  45.             {
  46.                 Console.WriteLine("space");
  47.             }
  48.  
  49.             spaceshipY++;
  50.             numberOfMoves--;
  51.         }
  52.     }
  53.  
  54.     private static bool IsInStarSystem(double starX, double starY, double spaceshipX, double spaceshipY)
  55.     {
  56.         if ((spaceshipX >= starX - 1 && spaceshipX <= starX + 1) && (spaceshipY >= starY - 1 && spaceshipY <= starY + 1))
  57.         {
  58.             return true;
  59.         }
  60.         else
  61.         {
  62.             return false;
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement