题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include<stdio.h> #include<string.h> int main(){ char str[20000]={0}; int x=0,y=0,num; gets(str); int l=strlen(str); for(int i=0;i<l;i++){ if(str[i]==';'&&(str[i-4]==';'||str[i-4]==NULL)){ if(str[i-2]>='0'&&str[i-2]<='9'&&str[i-1]>='0'&&str[i-1]<='9'){ num = (str[i-2]-48)*10+str[i-1]-48; if(str[i-3]=='A') x-=num; else if(str[i-3]=='D') x+=num; else if(str[i-3]=='W') y+=num; else if(str[i-3]=='S') y-=num; } } if(str[i]==';'&&(str[i-3]==';'||str[i-3]==NULL)){ if(str[i-1]>='0'&&str[i-1]<='9'){ num = str[i-1]-48; if(str[i-2]=='A') x-=num; else if(str[i-2]=='D') x+=num; else if(str[i-2]=='W') y+=num; else if(str[i-2]=='S') y-=num; } } } printf("%d,%d",x,y); }