题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <stdio.h> #include <string.h> int main() { char op[10000]; int x = 0, y = 0, len, i, j, num = 0; scanf("%s", op); len = strlen(op); for (i = 0; i < len; i++) { j = i + 1; num = 0; if (op[i] == 'A' || op[i] == 'W' || op[i] == 'D' || op[i] == 'S') { while (op[j] != ';') { if (op[j] >= '0' && op[j] <= '9') { num = num * 10 + (op[j] - '0'); j++; } else { break; } if (op[j] == ';') { if (i < 3) { switch (op[i]) { case 'A': x = x - num; break; case 'D': x = x + num; break; case 'W': y = y + num; break; case 'S': y = y - num; break; } } if (i > 3) { if (op[i - 1] == ';') { switch (op[i]) { case 'A': x = x - num; break; case 'D': x = x + num; break; case 'W': y = y + num; break; case 'S': y = y - num; break; } } } } } } } printf("%d,%d", x, y); return 0; }