题解 | 坐标移动

坐标移动

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

#include <bits/stdc++.h>
using namespace std;
int con(const string& a) {
    int b = 0;
    for (int j = a.length() - 2, c = 1; j >= 0; j--, c++) {
        b += pow(10, j) * (a[c] - '0');
    }
    return b;
}
int main() {
    string a;
    getline(cin, a);
    vector<string> b;
    istringstream c(a);
    string d;
    while (getline(c, d, ';')) {
        b.push_back(d);
    }
    pair<int, int> f = {0, 0};
    for (int i = 0; i < b.size(); i++) {
        string e = b[i];
        if (e.length() >= 4 || e.length() <= 1) {
            continue;
        }
        bool h = true;
        for (int j = 1; j < e.length(); j++) {
            if (e[j] >= '0' && e[j] <= '9') {
                continue;
            } else {
                h = false;
            }
        }
        if (h == false) {
            continue;
        }
        if (e[0] == 'A' || e[0] == 'S' || e[0] == 'W' || e[0] == 'D') {
            if (e[1] == 0) {
                continue;
            }
            if (e[0] == 'A') {
                int g = con(e);
                f.first = f.first - g;
            }
            if (e[0] == 'S') {
                int g = con(e);
                f.second = f.second - g;
            }
            if (e[0] == 'W') {
                int g = con(e);
                f.second = f.second + g;
            }
            if (e[0] == 'D') {
                int g = con(e);
                f.first = f.first + g;
            }
        } else {
            continue;
        }
    }
    cout << f.first << "," << f.second;
}

全部评论

相关推荐

06-15 18:44
黄淮学院 Java
Lynn012:如果是居民楼还是算了吧,看着有点野呢
点赞 评论 收藏
分享
ohs的小木屋:比不少实习待遇高了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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