题解 | #坐标移动#

坐标移动

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

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-27 20:15
点赞 评论 收藏
分享
AAA专业长城贴瓷砖刘大爷:这样的简历我会直接丢进垃圾桶,花里胡哨的
点赞 评论 收藏
分享
06-17 00:26
门头沟学院 Java
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend 智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem 选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的
点赞 评论 收藏
分享
牛客266927136号:为啥实习经历写这么少,项目经历反而大写特写,最重要的还是实习经历吧,写具体点,什么场景下做了什么事,解决了什么问题,优化了什么场景,性能提升了多少多少
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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