题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29?tpId=37&tags=&title=&difficulty=0&judgeStatus=0&rp=1&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37
#include<iostream> #include<queue> #include <bits/stdc++.h> using namespace std; int main() { string text; getline(cin, text); queue<string> que; string str; for(int i=0;i<text.length();i++) { if(text[i] != ';') { str += text[i]; }else { que.push(str); str = ""; } } que.push(str); pair<int,int> p(0,0); int n = que.size(); for(int j=0;j<n;j++){ string d; d=que.front(); que.pop(); if(d!=""){ if(regex_match(d.substr(1),regex("[0-9]*"))){ switch (d[0]) { case 'A': p.first -= stoi(d.substr(1)); break; case 'D': p.first += stoi(d.substr(1)); break; case 'W': p.second += stoi(d.substr(1)); break; case 'S': p.second -= stoi(d.substr(1)); break; default: break; } } } } cout << p.first << "," << p.second << endl; return 0; }