题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include "stdio.h" int main() { char str[10001]; gets(str); int i = 0; char dir = 0;//direction int dis = 0;//distance int x = 0; int y = 0; while(str[i]) { if(dir==0) { if(str[i]=='W'||str[i]=='A'||str[i] == 'S'||str[i] == 'D') dir = str[i]; else while(str[i]!=';')i++; i++; } else if(dir) { if(str[i]>='0'&&str[i]<='9') { dis = dis*10 + str[i] -'0'; i++; } else if(str[i]==';') { if(dis) switch(dir) { case 'A':x = x-dis; break; case 'S':y = y-dis; break; case 'W':y = y+dis; break; case 'D':x = x+dis; break; } dis = 0; dir = 0; i++; } else { while(str[i]!=';')i++; dis = 0; dir = 0; } } } printf("%d,%d",x,y); }#华为机试#