Advertisement
dimipan80

To the Stars!

May 11th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 KB | None | 0 0
  1. namespace _12.ToTheStars
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     class ToTheStars
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Dictionary<string, double[]> stars = new Dictionary<string, double[]>(3);
  11.             string[] inputs = Console.ReadLine()
  12.                     .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
  13.             for (int i = 0; i < 3; i++)
  14.             {
  15.                 string name = inputs[0].ToLower();
  16.                 double x = double.Parse(inputs[1]);
  17.                 double y = double.Parse(inputs[2]);
  18.  
  19.                 stars[name] = new double[] { x, y };
  20.  
  21.                 inputs = Console.ReadLine()
  22.                     .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
  23.             }
  24.  
  25.             double shipX = double.Parse(inputs[0]);
  26.             double shipY = double.Parse(inputs[1]);
  27.  
  28.             int moves = int.Parse(Console.ReadLine());
  29.  
  30.             for (int i = 0; i <= moves; i++, shipY++)
  31.             {
  32.                 CheckSpaceshipIsInTheRangeStarSystem(shipX, shipY, stars);
  33.             }
  34.         }
  35.  
  36.         private static void CheckSpaceshipIsInTheRangeStarSystem(double x, double y, Dictionary<string, double[]> stars)
  37.         {
  38.             bool isInRange = false;
  39.             foreach (var star in stars)
  40.             {
  41.                 double starMinX = star.Value[0] - 1;
  42.                 double starMaxX = star.Value[0] + 1;
  43.                 double starMinY = star.Value[1] - 1;
  44.                 double starMaxY = star.Value[1] + 1;
  45.  
  46.                 if (x >= starMinX && x <= starMaxX && y >= starMinY && y <= starMaxY)
  47.                 {
  48.                     Console.WriteLine(star.Key);
  49.                     isInRange = true;
  50.                     break;
  51.                 }
  52.             }
  53.  
  54.             if (!isInRange)
  55.             {
  56.                 Console.WriteLine("space");
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement