uva :: Programming Challenges :: Chapter 1-10189 - Minesweeper

 1 /* 
 2  * File:   10189.cpp
 3  * Author: GongZhi
 4  * Problem: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=29&page=show_problem&problem=1130
 5  * Created on 2009年7月25日, 下午9:08
 6  */
 7 
 8 #include <stdlib.h>
 9 #include <string.h>
10 #include <iostream>
11 #include <string>
12 #include <vector>
13 #include <map>
14 #include <queue>
15 using namespace std;
16 
17 /*
18  *
19  */
20 char ans[200][200];
21 int P[8][2= {
22     {01},
23     {0-1},
24     {10},
25     {-10},
26     {1-1},
27     {11},
28     {-11},
29     {-1-1}
30 };
31 
32 int main() {
33     int n, m, i, j, k, t,kase=1;
34     while (scanf("%d%d"&n, &m), n) {
35         for (i = 0; i < n; i++)scanf("%s", ans[i]);
36         for (i = 0; i < n; i++)
37             for (j = 0; j < m; j++) {
38                 if (ans[i][j] == '*')continue;
39                 t = 0;
40                 for (k = 0; k < 8; k++)
41                     if (i + P[k][0>= 0 && i + P[k][0< n && j + P[k][1>= 0 && j + P[k][1< m && ans[i + P[k][0]][j + P[k][1]] == '*')t++;
42                 ans[i][j] = '0' + t;
43             }
44             if(kase!=1)printf("\n");
45             printf("Field #%d:\n",kase++);
46             for(i=0;i<n;i++)printf("%s\n",ans[i]);
47     }
48     return 0;
49 }

posted on 2009-07-25 21:55 gong 阅读(917) 评论(1)  编辑 收藏 引用

评论

# re: uva :: Programming Challenges :: Chapter 1-10189 - Minesweeper 2011-02-21 16:57 陈泓旭

那个P[8][2]是怎么想到的呢?  回复  更多评论   


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


<2011年2月>
303112345
6789101112
13141516171819
20212223242526
272812345
6789101112

导航

统计

常用链接

留言簿(6)

随笔档案

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜