题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <cstdio> #include <iostream> #include <vector> using namespace std; bool judge(string n) { if(!(n[0]=='A'||n[0]=='S'||n[0]=='W'||n[0]=='D')) return false; string number=n.substr(1,n.size()); for(int i=0;i<number.size();i++) if(!(number[i]>='0'&&number[i]<='9')) return false; return true; } int main() { string n; vector<string> vc; int x=0,y=0; while(getline(cin,n,';')) { if(judge(n)) { string number=n.substr(1,n.size()-1); if(n[0]=='A') x-=stoi(number); else if(n[0]=='S') y-=stoi(number); else if(n[0]=='W') y+=stoi(number); else if(n[0]=='D') x+=stoi(number); } } cout<<x<<","<<y<<endl; } // 64 位输出请用 printf("%lld")