题解 | #坐标移动#

坐标移动

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;
}

全部评论

相关推荐

02-12 00:59
已编辑
哈尔滨工业大学 产品经理
华为 软件开发岗 20.6*16薪 本科
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务