posts - 17,  comments - 0,  trackbacks - 0
 1 #include <cstdlib>
 2 #include <iostream>
 3 
 4 
 5 using namespace std;
 6 
 7 char b[11][11],c[11][11];
 8 int main(int argc, char *argv[])
 9 {
10     int n,i,j,k,loss=0;
11         
12     scanf("%d",&n);
13     for(i=0;i<n;i++)
14     {        
15         scanf("%s",b[i]);                    
16     }    
17     for(i=0;i<n;i++)
18     {
19         scanf("%s",c[i]);                               
20     }
21 
22     
23     for(i=0;i<n;i++)
24     {
25         for(j=0;j<n;j++)
26         {
27             if((c[i][j]=='+')&&(b[i][j]!='*'))
28             {
29                 k=0;
30                 if(i-1>=0&&b[i-1][j]=='*')
31                 {           k++;                    
32                 }
33                 if(i+1<n&&b[i+1][j]=='*')
34                 {              k++;
35                 }
36                 if(j-1>=0&&b[i][j-1]=='*')
37                 {           k++;
38                 }
39                 if(j+1<n&&b[i][j+1]=='*')
40                 {           k++;                    
41                 }                
42                 if(i-1>=0&&j-1>=0&&b[i-1][j-1]=='*')
43                 {           k++;
44                 }
45                 if(i+1<n&&j+1<n&&b[i+1][j+1]=='*')
46                 {          k++;
47                 }
48                 if(i-1>=0&&j+1<n&&b[i-1][j+1]=='*')
49                 {         k++;
50                 }
51                 if(i+1<n&&j-1>=0&&b[i+1][j-1]=='*')
52                 {           k++;
53                 }
54                 b[i][j]=k+'0'
55             }else if((c[i][j]=='+')&&(b[i][j]=='*'))
56                      loss=1;     
57                 //printf("%c",b[i][j]);                                   
58         } 
59         //
60     }
61     
62     for(i=0;i<n;i++)
63     {
64         for(j=0;j<n;j++)
65         {
66             if(!loss)
67             {
68                 if(b[i][j]=='*')
69                     printf("#");
70                 else
71                     printf("%c",b[i][j]);
72             }                
73             else
74                 printf("%c",b[i][j]);
75         }
76         printf("\n");
77     }    
78     
79     system("PAUSE");
80     return EXIT_SUCCESS;
81 }
82 
posted on 2011-11-17 20:53 刘聪 阅读(194) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理