题解 | #坐标移动#

坐标移动

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

#include <bits/stdc++.h>
using namespace std;

int main() {
    int xx =0, yy =0;
    string s;
    getline(cin, s);
    string ss;
    vector<string> ssss;
    for(char sss:s) {
        if(sss!=';') {
            ss += sss;
        } else {
            ssss.push_back(ss);
            ss.clear();
        }
    }
    char x;
    int y=0;
    for(auto sssss:ssss) {
        if(sssss.size() == 2 || sssss.size() == 3) {
            if(sssss[0] == 'A' || sssss[0] =='S' || sssss[0] == 'W' || sssss[0] == 'D') {
                if(sssss[1] >= '0' && sssss[1] <= '9') {
                    string z;
                    if(sssss.size() ==3) {
                        if(sssss[2] >= '0' && sssss[2] <= '9') {
                            z = sssss.substr(1, 2);
                        } else continue;
                    } else {
                        z = sssss.substr(1, 2);
                    }
                    x = sssss[0];
                    y = stoi(z);
                } else continue;
            } else continue;
        } else continue;
        // cout << x << y <<endl;
        switch(x) {
            case 'A': xx -= y;
                break;
            case 'W': yy += y;
                break;
            case 'S': yy -= y;
                break;
            case 'D': xx += y;
                break;
            default: break;
        }
        // cout << xx <<','<< yy;

    } 
    cout << xx <<','<< yy;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
02-24 10:34
门头沟学院 Java
已注销:之前发最美的女孩基本爱答不理,发最帅的hr终于有反馈了,女孩子也要自信起来
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务