题解 | #坐标移动#

坐标移动

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

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

int main() {
    int x =0;
    int y =0;
    int xflag =1;
    int yflag =1;
    string str ;
    string str1;
    string str2;
    cin >> str;
    vector<string> v;
    for(auto c:str){
          if(c==';'){
            v.push_back(str1);
            str1.resize(0,'0');
            continue;
          }
          else{
            str1+=c;
          }
    }
    for(int i=0;i<v.size();i++){
        str2.resize(0);
        int count = 0;
        int n=0;
        xflag =1;
        yflag =1;
        for(auto c: v[i]){
            if(c=='A'||c=='S'||c=='W'||c=='D'){
               count++;
            }
        }   
        for(auto h: v[i]){
            if(count!=1||v[i][0]!='A'&&v[i][0]!='S'&&v[i][0]!='W'&&v[i][0]!='D'){
            break;
           }
            if(h=='A'){
                xflag = -1;
                yflag = 0;
                continue;
            }
            if(h=='S'){
                yflag = -1;
                xflag = 0;
                continue;
            }
            if(h=='W'){
                xflag =0;
                continue;
            }
            if(h=='D'){
                yflag=0;
                continue;
            }
            str2+=h;
            n++;
        }
        if(str2.size()){
        x+=(stoi(str2))*xflag;
        y+=(stoi(str2))*yflag;
        }
    }
    cout << x << ',' << y << endl; 
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

09-15 15:53
Java
Elastic90:我看到的是东软的人在耐心回应,而那位实习生跟在发疯似的
投递东软集团等公司10个岗位
点赞 评论 收藏
分享
10-13 16:58
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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