题解 | 坐标移动
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <bits/stdc++.h>
using namespace std;
int con(const string& a) {
int b = 0;
for (int j = a.length() - 2, c = 1; j >= 0; j--, c++) {
b += pow(10, j) * (a[c] - '0');
}
return b;
}
int main() {
string a;
getline(cin, a);
vector<string> b;
istringstream c(a);
string d;
while (getline(c, d, ';')) {
b.push_back(d);
}
pair<int, int> f = {0, 0};
for (int i = 0; i < b.size(); i++) {
string e = b[i];
if (e.length() >= 4 || e.length() <= 1) {
continue;
}
bool h = true;
for (int j = 1; j < e.length(); j++) {
if (e[j] >= '0' && e[j] <= '9') {
continue;
} else {
h = false;
}
}
if (h == false) {
continue;
}
if (e[0] == 'A' || e[0] == 'S' || e[0] == 'W' || e[0] == 'D') {
if (e[1] == 0) {
continue;
}
if (e[0] == 'A') {
int g = con(e);
f.first = f.first - g;
}
if (e[0] == 'S') {
int g = con(e);
f.second = f.second - g;
}
if (e[0] == 'W') {
int g = con(e);
f.second = f.second + g;
}
if (e[0] == 'D') {
int g = con(e);
f.first = f.first + g;
}
} else {
continue;
}
}
cout << f.first << "," << f.second;
}
查看1道真题和解析
