Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7. char *p, *s;
  8. int f = 1;
  9. int x = 0, y = 0;
  10. int x1 = 0, y1 = 0;
  11.  
  12. if (scanf("%m[A-z]", &p) == 1)
  13. {
  14. switch(p[0])
  15. {
  16. case 'N':
  17. scanf("%d", &x1);
  18. x += x1;
  19. break;
  20. case 'S':
  21. scanf("%d", &x1);
  22. x -= x1;
  23. break;
  24. case 'E':
  25. scanf("%d", &y1);
  26. y += y1;
  27. break;
  28. case 'W':
  29. scanf("%d", &y1);
  30. y -= y1;
  31. break;
  32. case 'T':
  33. f = 0;
  34. break;
  35. }
  36.  
  37. if (f == 0)
  38. {
  39. printf("%d %d", y, x);
  40. return 0;
  41. }
  42. free(p);
  43. }
  44.  
  45. while (scanf("%m[^A-z]", &s) == 1)
  46. {
  47. if (scanf("%m[A-z]", &p) == 1)
  48. {
  49. switch(p[0])
  50. {
  51. case 'N':
  52. scanf("%d", &x1);
  53. x += x1;
  54. break;
  55. case 'S':
  56. scanf("%d", &x1);
  57. x -= x1;
  58. break;
  59. case 'E':
  60. scanf("%d", &y1);
  61. y += y1;
  62. break;
  63. case 'W':
  64. scanf("%d", &y1);
  65. y -= y1;
  66. break;
  67. case 'T':
  68. f = 0;
  69. break;
  70. }
  71. if (f == 0)
  72. {
  73. printf("%d %d", y, x);
  74. free(s);
  75. free(p);
  76. return 0;
  77. }
  78. free(s);
  79. free(p);
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement