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