题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <vector> #include <iostream> using namespace std; int main() { string a; cin >> a; int x=0; int y=0; char c; int d=0; string s; string l; vector<string> v; int cn=0; for(auto e : a){ if(e != ';'){ s = s+e; } else { if(s != ""){ v.push_back(s); } s = ""; } } int f=0; for(auto e : v){ for(int i=0;i<e.size();i++){ if('a' <= e[i] && e[i] <= 'z' || 'A' <= e[i] && e[i] <= 'Z'){ c = e[i]; cn++; if(cn == 2){ f=1; break; } }else if('0' <= e[i] && e[i] <= '9'){ d = d*10 + e[i] - 48; //cout << "d" << d << endl; }else{ f=1; break; } } cn =0; //cout << c << d << endl; if(f != 1){ if(c == 'A'){ x = x-d; }else if(c == 'D'){ x=x+d; }else if(c == 'S'){ y=y-d; }else if(c == 'W'){ y=y+d; } } f =0; d =0; c = ' '; // cout << x << "," << y << endl; } cout << x << "," << y << endl; } // 64 位输出请用 printf("%lld")