1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| #include<bits/stdc++.h>
using namespace std;
int n; string s[101], tmp; int flag[101][101]; string target = "yizhong"; int dire[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
void search(){ for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){ if(s[i][j] != target[0]) continue; else for(int k = 0; k < 8; k++){ int xx = i + dire[k][0], yy = j + dire[k][1]; if(xx < 0 || yy < 0 || xx >= n || yy >= n) continue; int t = 1, index = 1; while(index < target.size()){ if(xx < 0 || yy < 0 || xx >= n || yy >= n || s[xx][yy] != target[index]){ t = 0; break; } xx += dire[k][0], yy += dire[k][1]; index++; } if(t){ index = 1, xx = i + dire[k][0], yy = j + dire[k][1]; while(index < target.size()){ flag[xx][yy] = 1; xx += dire[k][0], yy += dire[k][1]; index++; } flag[i][j] = 1; } } } }
void draw(){ for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){ if(flag[i][j] == 1) continue; else s[i][j]='*'; } }
void print(){ for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ cout<<s[i][j]; } cout<<endl; }
} int main(){ scanf("%d", &n); for(int i = 0; i < n; i++){ cin>>s[i]; } search(); draw(); print(); return 0; }
|