-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcpp.cpp
49 lines (43 loc) · 1.32 KB
/
cpp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#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();
// game loop
while (1) {
int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line.
cin >> remainingTurns; cin.ignore();
string move = "";
if (initialTY > lightY) {
move += 'N';
initialTY += -1;
}
else if (initialTY < lightY) {
move += 'S';
initialTY += 1;
}
if (initialTX > lightX) {
move += 'W';
initialTX += -1;
}
else if (initialTX < lightX) {
move += 'E';
initialTX += 1;
}
// A single line providing the move to be made: N NE E SE S SW W or NW
cout << move << endl;
}
}