题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include<iostream>
#include<string>
#include<vector>
using namespace std;
void getCoordinate(vector<int>& start, const string& str);
int main(){
string str;
while(cin >> str){
vector<int> beg(2, 0);
getCoordinate(beg, str);
cout << beg[0] << "," << beg[1] << endl;
}
return 0;
}
void getCoordinate(vector<int>& start, const string& str){
int i = 0;
int distance = 0;
char ch;
int count = 0;
while(i < str.size()){
if(str[i] == ';' && distance != 0 && count == 1){
if(ch == 'A'){ //左
start[0] -= distance;
}else if(ch == 'D'){ //右
start[0] += distance;
}else if(ch == 'W'){//上
start[1] += distance;
}else if(ch == 'S'){//下
start[1] -= distance;
}
distance = 0;
count = 0;
}else if(isalpha(str[i])){
ch = str[i];
count++;
}else if(isdigit(str[i])){
distance = distance * 10 + (str[i] - '0');
}else if(str[i] == ';' && count != 0){
count = 0;
distance = 0;
}
i++;
}
}
顺丰集团工作强度 322人发布
