题解 | #坐标移动#
坐标移动
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;
}