题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <iostream> #include <string> using namespace std; int main() { int x=0,y=0,n; string s,m; while(getline(cin, s,';')){ if(s.length()==3){ if(s[0]=='A'&&isdigit(s[1])&&isdigit(s[2])){ x-=((s[1]-'0')*10+(s[2]-'0'));continue; } if(s[0]=='D'&&isdigit(s[1])&&isdigit(s[2])){ x+=((s[1]-'0')*10+(s[2]-'0'));continue; } if(s[0]=='W'&&isdigit(s[1])&&isdigit(s[2])){ y+=((s[1]-'0')*10+(s[2]-'0'));continue; } if(s[0]=='S'&&isdigit(s[1])&&isdigit(s[2])){ y-=((s[1]-'0')*10+(s[2]-'0'));continue; } } if(s.length()==2){ if(s[0]=='A'&&isdigit(s[1])){ x-=(s[1]-'0');continue; } if(s[0]=='D'&&isdigit(s[1])){ x+=((s[1]-'0'));continue; } if(s[0]=='W'&&isdigit(s[1])){ y+=((s[1]-'0'));continue; } if(s[0]=='S'&&isdigit(s[1])){ y-=((s[1]-'0'));continue; } } } cout<<x<<','<<y;; } // 64 位输出请用 printf("%lld")