标签:
1 #include<iostream> 2 #include<stdio.h> 3 #include<algorithm> 4 #define MAXN 11 5 using namespace std; 6 7 char _m[MAXN][MAXN]; 8 char mark[MAXN][MAXN]; 9 int dig[MAXN][MAXN]; 10 11 int main() 12 { 13 //freopen("acm.acm","r",stdin); 14 int num; 15 int i; 16 int j; 17 int tem; 18 bool boo; 19 cin>>num; 20 boo = false; 21 for(i = 0; i < num; ++ i) 22 { 23 for(j = 0; j < num; ++ j) 24 { 25 cin>>_m[i][j]; 26 } 27 } 28 for(i = 0; i < num; ++ i) 29 { 30 for(j = 0; j < num; ++ j) 31 { 32 cin>>mark[i][j]; 33 } 34 } 35 for(i = 0; i < num; ++ i) 36 { 37 for(j = 0; j < num; ++ j) 38 { 39 tem = 0; 40 if(mark[i][j] == ‘x‘) 41 { 42 if(i > 0) 43 { 44 if(_m[i-1][j] == ‘*‘) 45 ++ tem; 46 } 47 if(i < num-1) 48 { 49 if(_m[i+1][j] == ‘*‘) 50 ++ tem; 51 } 52 if(j > 0) 53 { 54 if(_m[i][j-1] ==‘*‘) 55 ++ tem; 56 } 57 if(j < num-1) 58 { 59 if(_m[i][j+1] == ‘*‘) 60 ++ tem; 61 } 62 if(i > 0 && j > 0) 63 { 64 if(_m[i-1][j-1] == ‘*‘) 65 ++ tem; 66 } 67 if(i > 0&&j < num-1) 68 { 69 if(_m[i-1][j+1] == ‘*‘) 70 ++ tem; 71 } 72 if(i < num-1&&j > 0) 73 { 74 if(_m[i+1][j-1] == ‘*‘) 75 ++ tem; 76 } 77 if(i < num-1&&j < num-1) 78 { 79 if(_m[i+1][j+1] == ‘*‘) 80 ++ tem; 81 } 82 dig[i][j] = tem; 83 if(_m[i][j] == ‘*‘) 84 boo = true; 85 } 86 } 87 } 88 for(i = 0; i < num; ++ i) 89 { 90 for(j = 0; j < num; ++ j) 91 { 92 if(boo && _m[i][j] == ‘*‘) 93 cout<<_m[i][j]; 94 else if(mark[i][j] == ‘.‘) 95 cout<<mark[i][j]; 96 else 97 cout<<dig[i][j]; 98 } 99 cout<<endl; 100 } 101 }
标签:
原文地址:http://www.cnblogs.com/gavinsp/p/4568628.html