Problem F. NASSA’s Robot【大大大大大水题】_c++


题意

  • NASSA的机器人降落到了火星,降落的地方可以用X-Y坐标表示。机器人最开始在(0, 0)。由于传输问题,部分指令可能会混淆,现在给出确定的命令与未知命令,请帮忙确认机器人的X、Y坐标最小最大值分别是多少。
  • 输出格式为:
    X最小 Y最小 X最大 Y最大

题解

  • 还是大大大水题

AC-Code

#include <bits/stdc++.h>
using namespace std;

int main() {
int T; cin >> T;
while (T--) {
string s; cin >> s;
int x = 0, y = 0;
int cnt = 0;
for (int i = 0; i < s.length(); ++i) {
if (s[i] == 'U') ++y;
else if (s[i] == 'D') --y;
else if (s[i] == 'R') ++x;
else if (s[i] == 'L') --x;
else ++cnt;
}
cout << x - cnt << " " << y - cnt << " " << x + cnt << " " << y + cnt << endl;
}
return 0;
}