Advertisement
Asinka

01. Ship Damage (6 Dec 2011 Morning)

Dec 26th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4.  
  5. class Program
  6. {
  7.     static void Main()
  8.     {
  9.         int shipX1 = int.Parse(Console.ReadLine());
  10.         int shipY1 = int.Parse(Console.ReadLine());
  11.         int shipX2 = int.Parse(Console.ReadLine());
  12.         int shipY2 = int.Parse(Console.ReadLine());
  13.         int horizont = int.Parse(Console.ReadLine());
  14.         int damages = 0;      
  15.  
  16.         for (int i = 0; i < 3; i++)
  17.     {
  18.             int catapultX = int.Parse(Console.ReadLine());
  19.             int catapultY = int.Parse(Console.ReadLine());
  20.  
  21.             catapultY = horizont - catapultY;
  22.             if (i == 0)
  23.             {
  24.                 shipY1 = shipY1 - horizont;
  25.                 shipY2 = shipY2 - horizont;
  26.             }        
  27.  
  28.             if (catapultX > shipX1 && catapultX < shipX2 && catapultY > shipY1 && catapultY < shipY2)
  29.             {
  30.                 //inside the ship = 100%
  31.                 damages = damages + 100;              
  32.             }
  33.             else if (catapultX < shipX1 && catapultX > shipX2 && catapultY < shipY1 && catapultY > shipY2)
  34.             {
  35.                 //inside the ship = 100%
  36.                 damages = damages + 100;
  37.             }
  38.             else if (catapultX > shipX1 && catapultX < shipX2 && catapultY < shipY1 && catapultY > shipY2)
  39.             {
  40.                 //inside the ship = 100%
  41.                 damages = damages + 100;
  42.             }
  43.             else if (catapultX < shipX1 && catapultX > shipX2 && catapultY < shipY1 && catapultY > shipY2)
  44.             {
  45.                 //inside the ship = 100%
  46.                 damages = damages + 100;
  47.             }
  48.             else if ((catapultX == shipX1 || catapultX == shipX2) && (catapultY > shipY1 && catapultY < shipY2))
  49.             {
  50.                 //X sides of the ship = 50%
  51.                 damages = damages + 50;
  52.             }
  53.             else if ((catapultX == shipX1 || catapultX == shipX2) && (catapultY < shipY1 && catapultY > shipY2))
  54.             {
  55.                 //X sides of the ship = 50%
  56.                 damages = damages + 50;
  57.             }
  58.             else if ((catapultY == shipY1 || catapultY == shipY2) && (catapultX > shipX1 && catapultX < shipX2))
  59.             {
  60.                 //Y sides of the ship = 50%
  61.                 damages = damages + 50;
  62.             }
  63.             else if ((catapultY == shipY1 || catapultY == shipY2) && (catapultX < shipX1 && catapultX > shipX2))
  64.             {
  65.                 //Y sides of the ship = 50%
  66.                 damages = damages + 50;
  67.             }
  68.             else if ((catapultX == shipX1 && catapultY == shipY1) || (catapultX == shipX2 && catapultY == shipY2))
  69.             {
  70.                 //hit the corner = 25 %
  71.                 damages = damages + 25;
  72.             }
  73.             else if ((catapultX == shipX1 && catapultY == shipY2) || (catapultX == shipX2 && catapultY == shipY1))
  74.             {
  75.                 //hit the corner = 25 %
  76.                 damages = damages + 25;
  77.             }
  78.         }
  79.         Console.WriteLine(damages + "%");
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement