题解 | #坐标移动#

坐标移动

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 湖南

相关推荐

投递拓竹科技等公司10个岗位
点赞 评论 收藏
分享
苍蓝星上艾露:这简历。。。可以试试我写的开源简历优化工具https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
机械打工仔:我来告诉你原因,是因为sobb有在线简历,有些HR为了快会直接先看在线简历,初步感觉不合适就不会找你要详细的了
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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