一开始看讨论区一堆说要把 x 和 y 反着读的,结果反着读我却 WA 了。为啥我正常读没有错?
#include <iostream>
#include <string>
using namespace std;
const int N = 505;
int n, m, x, y;
int num[N][N], sum[N][N];
string s;
int main() {
cin >> n >> m >> x >> y >> s;
int len = s.size();
s = " " + s;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) num[i][j] = 1;
for (int i = 0; i < len; i++) {
if (s[i] == 'N') y++;
if (s[i] == 'S') y--;
if (s[i] == 'W') x--;
if (s[i] == 'E') x++;
num[x][y] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
sum[i][j] += num[i][j], num[i][j]++;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
cout << sum[j][n - i + 1] << " ";
cout << endl;
}
return 0;
}