题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include<bits/stdc++.h>
using namespace std;
int main() {
string str1;
getline(cin, str1);
int flag = 0;
vector<string> zuobiao;
vector<int> res(2, 0);
for (int i = 0; i < str1.size(); i++) {
if (str1[i] == ';') {
string tmp = str1.substr(flag, i - flag);
if (tmp.size() == 2 || tmp.size() == 3) {
if (tmp[0] == 'A' || tmp[0] == 'W' || tmp[0] == 'S' || tmp[0] == 'D') {
if (tmp[1] >= '0' && tmp[1] <= '9') {
if (tmp.size() == 3) {
if (tmp[2] >= '0' && tmp[2] <= '9') {
zuobiao.push_back(tmp);
}
}else{
zuobiao.push_back(tmp);
}
}
}
}
flag = i + 1;
}
}
for (int i = 0; i < zuobiao.size(); i++) {
char fangxiang = (char)zuobiao[i].at(0);
int num = atoi(&(zuobiao[i].substr(1, zuobiao[i].size() - 1))[0]);
switch (fangxiang) {
case'A':
res[0] -= num;
break;
case'D':
res[0] += num;
break;
case'W':
res[1] += num;
break;
case'S':
res[1] -= num;
break;
default:
break;
}
}
cout << res[0] << "," << res[1];
return 0;
}