Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. /**
  6. * Auto-generated code below aims at helping you parse
  7. * the standard input according to the problem statement.
  8. **/
  9. int main()
  10. {
  11. int LX; // the X position of the light of power
  12. int LY; // the Y position of the light of power
  13. int TX; // Thor's starting X position
  14. int TY; // Thor's starting Y position
  15. char *move;
  16. scanf("%d%d%d%d", &LX, &LY, &TX, &TY); fgetc(stdin);
  17.  
  18. // game loop
  19. while (1) {
  20. int E; // The level of Thor's remaining energy, representing the number of moves he can still make.
  21. scanf("%d", &E); fgetc(stdin);
  22. int Yd, Xd;
  23. Yd = LY - TY;
  24. Xd = LX - TX;
  25. if(abs(Xd) == abs(Yd)) {
  26. if(Xd > 0 && Yd < 0) {
  27. *move = 'NE';
  28. TX=TX+1; TY=TY-1;
  29. }
  30. if(Xd > 0 && Yd > 0) {
  31. *move = 'SE';
  32. TX=TX+1; TY=TY+1;
  33. }
  34. if(Xd < 0 && Yd < 0) {
  35. *move = 'NW';
  36. TX=TX-1; TY=TY-1;
  37. }
  38. if(Xd < 0 && Yd > 0) {
  39. *move = 'SW';
  40. TX=TX-1; TY=TY+1;
  41. }
  42. printf("%s\n", move);
  43. }
  44. if(abs(Xd) != abs(Yd)) {
  45. if(abs(Xd) > abs(Yd)) {
  46. if(Xd > 0) {
  47. *move = 'E';
  48. TX=TX+1;
  49. }
  50. if(Xd < 0) {
  51. *move = 'W';
  52. TX=TX-1;
  53. }
  54. }
  55. if(abs(Yd) > abs(Xd)) {
  56. if(Yd < 0) {
  57. *move = 'N';
  58. TY=TY-1;
  59. }
  60. if(Yd > 0) {
  61. *move = 'S';
  62. TY=TY+1;
  63. }
  64. }
  65. printf("%s\n", move);
  66. }
  67. }
  68. // Write an action using printf(). DON'T FORGET THE TRAILING \n
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement