题解 | #坐标移动#

坐标移动

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

#include #include #include

using namespace std;

int main(){ string str1; int x=0, y=0, current, idx; int i, j, k; getline(cin, str1); for(i=0; i<str1.size(); i=k+1){ for(k=i;str1[k]!=';';k++){ } current = 0; if(str1[i]=='A'||str1[i]=='D'||str1[i]=='W'||str1[i]=='S'){ for(j=i+1; j<= k-1; j++){ idx = 0; if(str1[j]-'0' >= 0 && str1[j] - '0' <= 9){ current += (str1[j] - '0')*pow(10, k-1-j); idx++; }else{ current = 0; break; } } switch(str1[i]){ case 'A': x -= current; break; case 'S': y -= current; break; case 'D': x += current; break; case 'W': y += current; break; } } } cout << x <<","<< y; return 0; }

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务