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; // Thor's starting X position
- int initialTY; // Thor's starting Y position
- cin >> lightX >> lightY >> initialTX >> initialTY; cin.ignore();
- int thorX = lightX - initialTX;
- int thorY = lightY - initialTY;
- char dir_name[4] = {'N', 'E', 'S', 'W'};
- // 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;
- cerr << to_string(thorX) << " " << to_string(thorY) << endl;
- char dir[2] = {'\0', '\0'};
- char *cd = &dir[0];
- if (thorY != 0)
- {
- *cd = thorY > 0 ? dir_name[2] : dir_name[0];
- thorY += thorY > 0? -1 : 1;
- cd = &dir[1];
- }
- if (thorX != 0)
- {
- *cd = thorX > 0 ? dir_name [1] : dir_name [3];
- thorX += thorX > 0 ? -1 : 1;
- }
- if (dir[1] != '\0') cout << dir[0] << dir[1] << endl;
- else cout << dir[0] << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement