题解 | #坐标移动#

坐标移动

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <sstream>
#include <string>
using namespace std;

int main() {
    string s;
    int x=0;
    int y=0;
    cin>>s;
    istringstream ss(s);
    string token;
    while(getline(ss,token,';')){
        if(token.length()==0){
            continue;
        }
        char cmd=token[0];
        if(token.length()==1){
            continue;
        }
        string d=token.substr(1);
        if(!all_of(d.begin(), d.end(),::isdigit)){
            continue;
        }
        int dd=stoi(d);
        if(cmd=='A'){
            x-=dd;
        }else if(cmd=='S'){
            y-=dd;
        }else if(cmd=='W'){
            y+=dd;
        }else if(cmd=='D'){
            x+=dd;
        }
    }
    cout<<x<<","<<y;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

Wy_m:只要不是能叫的上名的公司 去实习没有任何意义 不如好好沉淀自己
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务