题解 | #坐标移动#

坐标移动

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

全部评论

相关推荐

03-30 21:02
已编辑
武汉大学 Java
ALEX_BLX:虽然说聊天记录不可信,不过这个趋势确实如此但我觉得也要想到一点就是卷后端的人里真正有“料”的人又有多少,我说的这个料都不是说一定要到大佬那种级别,而是就一个正常的水平。即使是现在也有很多人是跟风转码的,2-3个月速成后端技术栈的人数不胜数,但今时不同往日没可能靠速成进大厂了。这种情况就跟考研一样,你能上考场就已经打败一半的人了
点赞 评论 收藏
分享
刘湘_passion:太强了牛肉哥有被激励到
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务