#include<bits/stdc++.h> using namespace std; int x,y; inline void movePeople(string number,char aim){ long long m = stoll(number); if(aim == 'A') x -= m; else if(aim == 'D') x += m; else if(aim == 'W') y += m; else if(aim == 'S') y -= m; } int main() { char c; bool vis = true; bool getChar = false; char aim; string number = "",s; getline(cin,s); for(char&c:s){ if(c == ';'){ if(vis and number.size()){ movePeople(number,aim); } vis = true; getChar = false; number = ""; }else{ if(!vis) continue; if(islower(c) or isupper(c)){ if(getChar) vis = false; else{ getChar = true; aim = c; } }else if(getChar) number += c; } } cout << x << ',' << y << endl; }
单纯的简单模拟走一遍就可以了。
这里注意变量名的作用域