Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- char *p, *s;
- int f = 1;
- int x = 0, y = 0;
- int x1 = 0, y1 = 0;
- if (scanf("%m[A-z]", &p) == 1)
- {
- switch(p[0])
- {
- case 'N':
- scanf("%d", &x1);
- x += x1;
- break;
- case 'S':
- scanf("%d", &x1);
- x -= x1;
- break;
- case 'E':
- scanf("%d", &y1);
- y += y1;
- break;
- case 'W':
- scanf("%d", &y1);
- y -= y1;
- break;
- case 'T':
- f = 0;
- break;
- }
- if (f == 0)
- {
- printf("%d %d", y, x);
- return 0;
- }
- free(p);
- }
- while (scanf("%m[^A-z]", &s) == 1)
- {
- if (scanf("%m[A-z]", &p) == 1)
- {
- switch(p[0])
- {
- case 'N':
- scanf("%d", &x1);
- x += x1;
- break;
- case 'S':
- scanf("%d", &x1);
- x -= x1;
- break;
- case 'E':
- scanf("%d", &y1);
- y += y1;
- break;
- case 'W':
- scanf("%d", &y1);
- y -= y1;
- break;
- case 'T':
- f = 0;
- break;
- }
- if (f == 0)
- {
- printf("%d %d", y, x);
- free(s);
- free(p);
- return 0;
- }
- free(s);
- free(p);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement