题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <iostream> #include <vector> #include <string> #include <stdio.h> using namespace std; struct move{ int x; int y; }; int main() { string a; struct move b={0,0}; vector<string>v; cin>>a; int pos=0; int start =0; while(pos<a.size()){ pos = a.find(";",start); string str; str = a.substr(start,pos-start); if(str!=""&&str.rfind("A")!=2){ v.push_back(str); } start = pos+1; } for(vector<string>::iterator it =v.begin();it!=v.end();it++){ string str; string s; int number=0; str = (*it).substr(0,1); s = (*it).substr(1,2); number = atoi(s.c_str()); if(str=="A"){ b.x -= number; }else if(str=="D"){ b.x += number; }else if(str=="W"){ b.y += number; }else if(str=="S"){ b.y -= number; } } cout<<b.x<<","<<b.y<<endl; } // 64 位输出请用 printf("%lld")