题解 | #坐标移动#

坐标移动

https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29

#include <iostream>
#include <string>
#include <regex>

int main() {
    std::string inp;

    int x = 0;
    int y = 0;

    while (std::getline(std::cin, inp, ';')) {
        if (inp.empty()) continue;
        std::string num_str = inp.substr(1);
        if (num_str.empty()) continue;

        if (std::regex_match(num_str, std::regex("[0-9]*"))) {
            int value = std::stoi(num_str);

            switch(inp[0]) {
                case 'A': x -= value;break;
                case 'D': x += value;break;
                case 'W': y += value;break;
                case 'S': y -= value;break;
                default: break;
            }
        }
    }

    std::cout << x << "," << y << std::endl;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 17:13
想去,但是听说加班强度实在难崩,所以拒绝了,现在有点心梗对面hr感觉也是实习生,打电话的时候怪紧张的,但是感觉人很好嘞
水中水之下水道的鼠鼠:哥们这不先去体验一下,不行再跑呗,大不了混个实习经历(有更好的转正offer就当我没说)
点赞 评论 收藏
分享
ZywOo_求职版:谁问你了....
投递字节跳动等公司9个岗位
点赞 评论 收藏
分享
求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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