Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- * ---
- * Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders.
- **/
- int main()
- {
- int lightX; // the X position of the light of power
- int lightY; // the Y position of the light of power
- int initialTX, thorx; // Thor's starting X position
- int initialTY, thory; // Thor's starting Y position
- cin >> lightX >> lightY >> initialTX >> initialTY; cin.ignore();
- thorx = initialTX, thory = initialTY;
- // game loop
- while (1) {
- int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line.
- cin >> remainingTurns; cin.ignore();
- // Write an action using cout. DON'T FORGET THE "<< endl"
- // To debug: cerr << "Debug messages..." << endl;
- int distanceX = lightX - thorx;
- int distanceY = lightY - thory;
- if (abs(distanceX) == abs(distanceY))
- {
- if (distanceX > 0 && distanceY > 0)
- {
- cout << "SE" << endl;
- thorx ++;
- thory ++;
- }
- else if (distanceX > 0 && distanceY < 0)
- {
- cout << "NE" << endl;
- thorx ++;
- thory -= 1;
- }
- else if (distanceX < 0 && distanceY > 0)
- {
- cout << "SW" << endl;
- thorx -= 1;
- thory ++ ;}
- else
- {
- cout << "NW" << endl;
- thorx -= 1;
- thory -= 1;
- }
- }
- if (abs(distanceX) > abs(distanceY))
- {
- if (distanceX > 0)
- {
- cout << "E" <<endl;
- thorx ++;}
- else
- {
- cout << "W" << endl;
- thorx -=1;}
- }
- if (abs(distanceX) < abs(distanceY))
- {
- if (distanceY > 0)
- {
- cout << "S" << endl;
- thory ++;
- }
- else
- {
- cout << "N" << endl;
- thory -= 1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement