题解 | #坐标移动#

坐标移动

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

#include<stdio.h>
#include<malloc.h>
#include<string.h>

int main() {
    char str[10000];
    int len;
    int x = 0, y = 0, num = 0;
    int i = 0, j = 0;
    scanf("%s", str);
    len = strlen(str);
    for (i = 0; i < len; i++) {
        if (str[i] == 'A' || str[i] == 'D' || str[i] == 'W' || str[i] == 'S') {
            for (j = i + 1, num = 0; j < len; j++) {
                if (str[j] >= '0' && str[j] <= '9') //数字字符
                    num = num * 10 + str[j] - '0'; //转为两位整数
                else
                    break;
            }
            if (str[j] == ';' && num) {
                if (str[i] == 'A')         x -= num;
                else if (str[i] == 'D')    x += num;
                else if (str[i] == 'W')    y += num;
                else if (str[i] == 'S')    y -= num;
            }

            i = j;
        }
        do {
            if (str[i] == ';')
                break;
        } while (++i < len);

    }
    printf("%d,%d", x, y);
}

C语言刷题 文章被收录于专栏

自己从头开始刷的C语言

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 15:37
点赞 评论 收藏
分享
这是什么操作什么意思,这公司我服了...
斯派克spark:意思是有比你更便宜的牛马了
点赞 评论 收藏
分享
06-07 00:00
已编辑
腾讯_后端开发
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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