题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
/*没看到最高两位数的情况下做的,可以识别位数,并输出*/
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
using namespace std;
void movement(string str)
{
vector<string> v;
int x = 0, y = 0;
int sub = 0;
string s0;
for (int i = 0; i < str.size(); i++)
{
if (str[i] != ';')
{
sub++;
s0.push_back(str[i]);
continue;
}
else
{
v.push_back(s0);
sub = 0;
s0.clear();
continue;
}
}
vector<int> num;
num.resize(v.size());
for (int i = 0; i < v.size(); i++)
{
int len = v[i].size();
for (int j = 1; j < len; j++)
{
if (v[i][j] >= '0' && v[i][j] <= '9')
{
num[i] += (v[i][j] - '0') * pow(10, len - 1 - j);
continue;
}
else
{
v[i] = "False";
break;
}
}
}
for (int i = 0; i < v.size(); i++)
{
switch (v[i][0])
{
case'A':
x -= num[i]; break;
case'D':
x += num[i]; break;
case'W':
y += num[i]; break;
case'S':
y -= num[i]; break;
default:
break;
}
}
cout << x << "," << y << endl;
}
int main()
{
string s;
getline(cin, s);
movement(s);
return 0;
}
// 64 位输出请用 printf("%lld")