题解 | #坐标移动#

坐标移动

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

#include <iostream>
using namespace std;

int main() {
    string str;
    cin >> str;
    int x = 0, y = 0;
 
    for(int i = 0; i < str.size();){
        for(int j = 0; i+j < str.size();){
           
            if(str[i+j] != ';'){
                j++;
            }else{
                if(j == 3){
                    if(str[i+1]>= '0' && str[i+1] <= '9' && str[i+2] >= '0' && str[i+2] <= '9'){
                        if(str[i] == 'A' ){
                            x -= (str[i+1]-'0')*10+(str[i+2]-'0');
                        }else if(str[i] == 'D'){
                            x += (str[i+1]-'0')*10+(str[i+2]-'0');
                        }else if(str[i] == 'S'){
                            y -= (str[i+1]-'0')*10+(str[i+2]-'0');
                        }else{
                            y += (str[i+1]-'0')*10+(str[i+2]-'0');
                        }
                    } 
                    
                }else if(j == 2){
                    if(str[i+1] >= '0' && str[i+1] <= '9'){
                       if(str[i] == 'A' ){
                            x -= (str[i+1]-'0');
                        }else if(str[i] == 'D'){
                            x += (str[i+1]-'0');
                        }else if(str[i] == 'S'){
                            y -= (str[i+1]-'0');
                        }else{
                            y += (str[i+1]-'0');
                        } 
                    }
                }

                //cout << x << " " << y << endl;
                i = i+j+1;
                j = 0;
            }
        }
        
    }

    cout << x << ',' << y << endl;

    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论
大佬看一下私信呀
点赞 回复 分享
发布于 2023-09-13 21:49 湖南

相关推荐

不愿透露姓名的神秘牛友
07-30 11:34
真的很糟糕:黑奴听了都流泪啊
点赞 评论 收藏
分享
昨天 17:57
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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