题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <iostream> using namespace std; int main() { int x = 0, y = 0; int move; string str; cin >> str; for(int i = 0, j = 0; i < str.length(); i ++){ if(str[i] == ';'){ if(i - j == 3){ if((str[j] == 'A' || str[j] == 'D' ||str[j] == 'W' ||str[j] == 'S')&&str[j+1] >= 48&&str[j+1] <= 58 && str[j+2] >= 48 && str[j+2]<=58){ if(str[j] == 'W'){ move = 10*(str[j+1]-48) + str[j+2]-48; y+=move; } if(str[j] == 'S'){ move = 10*(str[j+1]-48) + str[j+2]-48; y-=move; } if(str[j] == 'A'){ move = 10*(str[j+1]-48) + str[j+2]-48; x-=move; } if(str[j] == 'D'){ move = 10*(str[j+1]-48) + str[j+2]-48; x+=move; } } } if(i - j == 2){ if((str[j] == 'A' || str[j] == 'D' ||str[j] == 'W' ||str[j] == 'S')&&str[j+1] >= 48&&str[j+1] <= 58){ if(str[j] == 'W'){ move = str[j+1]-48; y+=move; } if(str[j] == 'S'){ move = str[j+1]-48; y-=move; } if(str[j] == 'A'){ move = str[j+1]-48; x-=move; } if(str[j] == 'D'){ move = str[j+1]-48; x+=move; } } } j = i + 1; } } cout << x << "," << y; return 0; } // 64 位输出请用 printf("%lld")