题解 | #坐标移动#

坐标移动

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


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

#define MAX 10001

int main()
{
    char str[MAX];
    scanf("%s",str);
    char *p=str;
    char d=0x00;
    int n=0;
    int x=0;
    int y=0;
    
    while(*p != '\0')
    {
        if(!d)
        {
            if(*p =='A'||*p=='S'||*p=='D'||*p=='W')
            {
                d=*p;
                p++;
                //printf("%c%c\r\n",d,*p);
                continue;
            }
            else if(*p != ';' && *p != '\0')
            {
                p++;
            }
        }
        if(d)
        {
            if( *p >= '0' && *p <= '9')
            {
                //printf("n1=%d\r\n",n);
                n *= 10;
                //printf("n2=%d\r\n",n);
                n += *p -'0';
                //printf("n3=%d\r\n",n);
            }
            else if(*p ==';')
            {
                if (d=='A')
                {
                    x -= n;
                    //printf("xA=%d\r\n",x);
                }
                else if (d =='D')
                {
                    x += n;
                    //printf("xD=%d\r\n",x);
                }
                else if (d == 'W')
                {
                    y += n;
                    //printf("yW=%d\r\n",x);
                }
                else if (d=='S')
                {
                    y -= n;
                    //printf("yS=%d\r\n",x);
                }
                d=0;
                n=0;
            }
            else
            {
                d=0;
                n=0;
            }
        }
        p++;
    }
    printf("%d,%d",x,y);
    return 0;
}
全部评论

相关推荐

06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
06-10 23:36
已编辑
首都经济贸易大学 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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