一道简单的模拟题,代码写得太水,卡了很长时间,碰上我这样的坑爹队友也是不幸啊
#include <bits/stdc++.h>
using namespace std;
int mov[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};
map <char, int> dir;
int n;
int check(int x, int y) {
return x >= 1 && x <= n && y >= 1 && y <= n;
}
int main() {
dir['N'] = 0;
dir['W'] = 1;
dir['S'] = 2;
dir['E'] = 3;
while(~scanf("%d", &n) && n) {
char dir1[2], dir2[2];
int v1, t1, v2, t2;
scanf("%s%d%d", dir1, &v1, &t1);
scanf("%s%d%d", dir2, &v2, &t2);
int k;
scanf("%d", &k);
int x1, y1, x2, y2;
int ndir1, ndir2;
ndir1 = dir[dir1[0]]; ndir2 = dir[dir2[0]];
x1 = y1 = 1;
x2 = y2 = n;
for (int j = 1; j <= k; j++) {
int tx1 = x1, ty1 = y1;
for (int i = 0; i < v1; i++) {
tx1 = tx1 + mov[ndir1][0];
ty1 = ty1 + mov[ndir1][1];
if (!check(tx1, ty1)) {
tx1 = tx1 - mov[ndir1][0];
ty1 = ty1 - mov[ndir1][1];
ndir1 = (ndir1 + 2) % 4;
i--;
}
}
x1 = tx1; y1 = ty1;
int tx2 = x2, ty2 = y2;
for (int i = 0; i < v2; i++) {
tx2 = tx2 + mov[ndir2][0];
ty2 = ty2 + mov[ndir2][1];
if (!check(tx2, ty2)) {
tx2 = tx2 - mov[ndir2][0];
ty2 = ty2 - mov[ndir2][1];
ndir2 = (ndir2 + 2) % 4;
i--;
}
}
x2 = tx2; y2 = ty2;
if (x1 == x2 && y1 == y2) {
swap(ndir1, ndir2);
}
else {
if (j % t1 == 0) {
ndir1 = (ndir1 + 1) % 4;
}
if (j % t2 == 0) {
ndir2 = (ndir2 + 1) % 4;
}
}
}
printf("%d %d\n", x1, y1);
printf("%d %d\n", x2, y2);
}
return 0;
}