Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- int main()
- {
- int LX; // the X position of the light of power
- int LY; // the Y position of the light of power
- int TX; // Thor's starting X position
- int TY; // Thor's starting Y position
- char *move;
- scanf("%d%d%d%d", &LX, &LY, &TX, &TY); fgetc(stdin);
- // game loop
- while (1) {
- int E; // The level of Thor's remaining energy, representing the number of moves he can still make.
- scanf("%d", &E); fgetc(stdin);
- int Yd, Xd;
- Yd = LY - TY;
- Xd = LX - TX;
- if(abs(Xd) == abs(Yd)) {
- if(Xd > 0 && Yd < 0) {
- *move = 'NE';
- TX=TX+1; TY=TY-1;
- }
- if(Xd > 0 && Yd > 0) {
- *move = 'SE';
- TX=TX+1; TY=TY+1;
- }
- if(Xd < 0 && Yd < 0) {
- *move = 'NW';
- TX=TX-1; TY=TY-1;
- }
- if(Xd < 0 && Yd > 0) {
- *move = 'SW';
- TX=TX-1; TY=TY+1;
- }
- printf("%s\n", move);
- }
- if(abs(Xd) != abs(Yd)) {
- if(abs(Xd) > abs(Yd)) {
- if(Xd > 0) {
- *move = 'E';
- TX=TX+1;
- }
- if(Xd < 0) {
- *move = 'W';
- TX=TX-1;
- }
- }
- if(abs(Yd) > abs(Xd)) {
- if(Yd < 0) {
- *move = 'N';
- TY=TY-1;
- }
- if(Yd > 0) {
- *move = 'S';
- TY=TY+1;
- }
- }
- printf("%s\n", move);
- }
- }
- // Write an action using printf(). DON'T FORGET THE TRAILING \n
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement