更多操作
无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
cpp | <pre><code class="language-cpp">int main() | ||
int | |||
{ | { | ||
cin.tie(0)->sync_with_stdio(0); | |||
cout.tie(0); | |||
int n, k; | |||
cin >> n >> k; | |||
while (k--) | |||
{ | |||
int x, y; | |||
cin >> x >> y; | |||
string op; | |||
cin >> op; | |||
for (int i = 0; i < op.size(); i++) | |||
{ | |||
int tx = x, ty = y; | |||
if (op[i] == 'f') | |||
ty++; | |||
else if (op[i] == 'b') | |||
ty--; | |||
else if (op[i] == 'l') | |||
tx--; | |||
else | |||
tx++; | |||
if (tx >= 1 and tx <= n and ty >= 1 and ty <= n) | |||
{ | |||
x = tx, y = ty; | |||
} | |||
} | |||
cout << x << ' ' << y << '\n'; | |||
} | |||
} | } | ||
</code></pre> |
2025年1月19日 (日) 11:05的版本
<code class="language-cpp">int main() { cin.tie(0)->sync_with_stdio(0); cout.tie(0); int n, k; cin >> n >> k; while (k--) { int x, y; cin >> x >> y; string op; cin >> op; for (int i = 0; i < op.size(); i++) { int tx = x, ty = y; if (op[i] == 'f') ty++; else if (op[i] == 'b') ty--; else if (op[i] == 'l') tx--; else tx++; if (tx >= 1 and tx <= n and ty >= 1 and ty <= n) { x = tx, y = ty; } } cout << x << ' ' << y << '\n'; } } </code>