题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <bits/stdc++.h>
using namespace std;
int main() {
int xx =0, yy =0;
string s;
getline(cin, s);
string ss;
vector<string> ssss;
for(char sss:s) {
if(sss!=';') {
ss += sss;
} else {
ssss.push_back(ss);
ss.clear();
}
}
char x;
int y=0;
for(auto sssss:ssss) {
if(sssss.size() == 2 || sssss.size() == 3) {
if(sssss[0] == 'A' || sssss[0] =='S' || sssss[0] == 'W' || sssss[0] == 'D') {
if(sssss[1] >= '0' && sssss[1] <= '9') {
string z;
if(sssss.size() ==3) {
if(sssss[2] >= '0' && sssss[2] <= '9') {
z = sssss.substr(1, 2);
} else continue;
} else {
z = sssss.substr(1, 2);
}
x = sssss[0];
y = stoi(z);
} else continue;
} else continue;
} else continue;
// cout << x << y <<endl;
switch(x) {
case 'A': xx -= y;
break;
case 'W': yy += y;
break;
case 'S': yy -= y;
break;
case 'D': xx += y;
break;
default: break;
}
// cout << xx <<','<< yy;
}
cout << xx <<','<< yy;
return 0;
}
// 64 位输出请用 printf("%lld")

查看10道真题和解析