题解 | #坐标移动#

坐标移动

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

全部评论

相关推荐

07-08 13:48
门头沟学院 C++
点赞 评论 收藏
分享
小叮当411:应该是1-3个月吧
点赞 评论 收藏
分享
06-02 15:17
门头沟学院 Java
心爱的idea:怎么会呢 应该是打招呼有问题 问就说实习6个月全国可飞随时到岗
点赞 评论 收藏
分享
05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务