Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class ShipDamage
- {
- static void Main()
- {
- //Telerik Academy
- //Inside the sea (a standard Cartesian /rectangular/ coordinate system) we are given a ship S (a rectangle whose sides are parallel to the coordinate axes), a horizontal line H (the horizon) and three catapults, given as coordinates C1, C2 and C3 that will be used to fire the ship. When the attack starts, each catapult hits a projectile exactly into the positions that are symmetrical to C1, C2 and C3 with respect to the horizon H. When a projectile hits some of the corners of the ship, it causes a damage of 25%, when it hits some of the sides of the ship, the damage caused is 50% and when it hits the internal body of the ship, the damage is 100%. When the projectile hit outside of the ship, there is no damage. The total damage is sum of the separate damages and can exceed 100%.
- //Your task is to write a program that calculates the total damage caused after the attack over the ship.
- int shipX1 = int.Parse(Console.ReadLine());
- int shipY1 = int.Parse(Console.ReadLine());
- int shipX2 = int.Parse(Console.ReadLine());
- int shipY2 = int.Parse(Console.ReadLine());
- int horizonY = int.Parse(Console.ReadLine());
- int catapultX1 = int.Parse(Console.ReadLine());
- int catapultY1 = int.Parse(Console.ReadLine());
- int catapultX2 = int.Parse(Console.ReadLine());
- int catapultY2 = int.Parse(Console.ReadLine());
- int catapultX3 = int.Parse(Console.ReadLine());
- int catapultY3 = int.Parse(Console.ReadLine());
- int totalDamage = 0;
- //mirror the catapults Y positon to know the proyectile Y coordinate.
- int mirroredCatapultY1 = -(catapultY1 - horizonY);
- int mirroredCatapultY2 = -(catapultY2 - horizonY);
- int mirroredCatapultY3 = -(catapultY3 - horizonY);
- int horizonedShipY1 = shipY1 - horizonY;
- int horizonedShipY2 = shipY2 - horizonY;
- //Define the ship's rectangle area
- int shipTop = Math.Max(horizonedShipY1, horizonedShipY2);
- int shipBottom = Math.Min(horizonedShipY1, horizonedShipY2);
- int shipLeft = Math.Min(shipX1, shipX2);
- int shipRight = Math.Max(shipX1, shipX2);
- //Catapult 1
- if (mirroredCatapultY1 > shipBottom && mirroredCatapultY1 < shipTop)
- {
- if (catapultX1 > shipLeft && catapultX1 < shipRight) //Inside the ship
- {
- totalDamage += 100;
- }
- else if (catapultX1 == shipLeft || catapultX1 == shipRight)
- {
- totalDamage += 50; //On the Y sides
- }
- }
- if (mirroredCatapultY1 == shipBottom || mirroredCatapultY1 == shipTop)
- {
- if (catapultX1 == shipLeft || catapultX1 == shipRight)
- {
- totalDamage += 25; //In the corners
- }
- else if (catapultX1 > shipLeft && catapultX1 < shipRight)
- {
- totalDamage += 50; //On the X side
- }
- }
- //Catapult 2
- if (mirroredCatapultY2 > shipBottom && mirroredCatapultY2 < shipTop)
- {
- if (catapultX2 > shipLeft && catapultX2 < shipRight) //Inside the ship
- {
- totalDamage += 100;
- }
- else if (catapultX2 == shipLeft || catapultX2 == shipRight)
- {
- totalDamage += 50; //On the Y sides
- }
- }
- if (mirroredCatapultY2 == shipBottom || mirroredCatapultY2 == shipTop)
- {
- if (catapultX2 == shipLeft || catapultX2 == shipRight)
- {
- totalDamage += 25; //In the corners
- }
- else if (catapultX2 > shipLeft && catapultX2 < shipRight)
- {
- totalDamage += 50; //On the X side
- }
- }
- //Catapult 3
- if (mirroredCatapultY3 > shipBottom && mirroredCatapultY3 < shipTop)
- {
- if (catapultX3 > shipLeft && catapultX3 < shipRight) //Inside the ship
- {
- totalDamage += 100;
- }
- else if (catapultX3 == shipLeft || catapultX3 == shipRight)
- {
- totalDamage += 50; //On the Y sides
- }
- }
- if (mirroredCatapultY3 == shipBottom || mirroredCatapultY3 == shipTop)
- {
- if (catapultX3 == shipLeft || catapultX3 == shipRight)
- {
- totalDamage += 25; //In the corners
- }
- else if (catapultX3 > shipLeft && catapultX3 < shipRight)
- {
- totalDamage += 50; //On the X side
- }
- }
- Console.WriteLine(totalDamage + "%");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement