题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <iostream> using namespace std; int main() { int x = 0 , y = 0 , step = 0 ,dis = 0; char a; while(a != '\n'){ a = getchar(); if(a == '\n'){ break; }else if(a == ';'){ if(step == 11) y += dis; else if (step == 12) y -= dis; else if (step == 13) x -= dis; else if (step == 14) x += dis; dis = 0; step = 0; }else if(step == 0){ if(a == 'W') step = 11; else if(a == 'S') step = 12; else if(a == 'A') step = 13; else if(a == 'D') step = 14; else step = -1; }else if(step > 10){ if(a >= '0' && a <= '9'){ dis = dis * 10 + a -'0'; }else{ step = -1; } } } cout<<x<<","<<y; }