题解 | #坐标移动#

坐标移动

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]{1,2}"))) {
            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;
}

全部评论

相关推荐

看到这个内容真是闹麻了。。。。。。现在有了AI以后很多人面试都会作弊吗?&nbsp;那对老老实实面试的人岂不是不公平....
程序员牛肉:公平那是对小孩子讲的童话故事,成年人的世界只有能不能接受失败的后果。 你要是能接受面试作弊被发现之后多家公司联合永久拉黑的后果,你就搞。
点赞 评论 收藏
分享
一表renzha:手写数字识别就是一个作业而已
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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