题解 | #坐标移动#

坐标移动

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

定义了一堆变量。。。。
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int i,j,k,l;
    int h=0,g=0,move,abs=0,orb=0;
    int flag=0,len=0;
    char str[4000],num[100];
    scanf("%s",str);
    for(i=0;str[i]!='\0';i++)
    {
        len++;
        j=i;
        if(str[j]==';'&&str[j]!='\0')
        {
            len-=1;
            k=j-len;
            if(str[k]=='A'||str[k]=='S'||str[k]=='W'||str[k]=='D')
            {
                l=k+1;
                for(l;l<i;l++)
                {
                    if(str[l]>='0'&&str[l]<='9')
                    {
                        num[h]=str[l];
                        h++;
                        g++;
                    }
                    else
                    {
                        for(h=0;h<g;h++)
                        {
                            num[h]='\0';
                        }
                        flag=1;
                        h=0;
                        g=0;
                        break;
                    }
                }
                if(flag==0)
                {
                    move=atoi(num);
                    if(str[k]=='A')
                    {
                        abs-=move;
                    }
                    else if(str[k]=='D')
                    {
                        abs+=move;
                    }
                    else if(str[k]=='W')
                    {
                        orb+=move;
                    }
                    else if(str[k]=='S')
                    {
                        orb-=move;
                    }
                    for(h=0;h<g;h++)
                        {
                            num[h]='\0';
                        }
                    h=0;
                    g=0;
                }
                if(flag==1)
                {
                    flag=0;
                }
            }
            len=0;
        }
    }
    printf("%d,%d",abs,orb);
}

全部评论

相关推荐

三年之期已到我的offer快到碗里来:9硕都比不上9本
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-27 10:28
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务