P1101 单词方阵 (单词方阵)
思路:就是白白的模拟
#include<iostream> using namespace std; int f[110][110]; char cc[110][110]; char kk[] = "yizhong"; int n; void ff(int x, int y, int a, int b){ bool flag = 1; int xx, yy; for (int i = 0; i < 7; ++i){ xx = x + a*i; yy = y + b*i; if (!(xx >= 0 && xx < n&&yy >= 0 && yy < n) || (cc[xx][yy] != kk[i])){ flag = 0; break; } } if (flag)for (int i = 0; i < 7; ++i){ xx = x + a*i; yy = y + b*i; f[xx][yy] = 1; } } int main(){ cin >> n; for (int i = 0; i < n; ++i) cin >> cc[i]; for (int i = 0; i < n;++i) for (int j = 0; j < n;++j) if (cc[i][j] == 'y'){ ff(i, j, 0, 1); ff(i, j, 1, 0); ff(i, j, 0, -1); ff(i, j, -1, 0); ff(i, j, 1, 1); ff(i, j, -1, -1); ff(i, j, -1, 1); ff(i, j, 1, -1); } for (int i = 0; i < n; ++i){ for (int j = 0; j < n;++j) if (f[i][j] == 0)cout << "*"; else cout << cc[i][j]; cout << endl; } }