题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <algorithm> #include <bits/stdc++.h> #include <cctype> #include <sstream> #include <string> using namespace std; int main() { string s; int x=0; int y=0; cin>>s; istringstream ss(s); string token; while(getline(ss,token,';')){ if(token.length()==0){ continue; } char cmd=token[0]; if(token.length()==1){ continue; } string d=token.substr(1); if(!all_of(d.begin(), d.end(),::isdigit)){ continue; } int dd=stoi(d); if(cmd=='A'){ x-=dd; }else if(cmd=='S'){ y-=dd; }else if(cmd=='W'){ y+=dd; }else if(cmd=='D'){ x+=dd; } } cout<<x<<","<<y; } // 64 位输出请用 printf("%lld")