Crosswor Answers,(UVa, 232)

Emmm....第一篇博客。

打算要把《算法竞赛-入门经典(2版)》所有题刷一遍写题解,做评注。

题目链接:https://vjudge.net/problem/UVA-232

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define maxn 20
 4 char map[maxn][maxn];
 5 
 6 int main()
 7 {
 8     int r,c,count = 1;
 9     while(1)
10     {
11         int point = 1;
12         scanf("%d",&r);
13         if(r==0)
14         break;
15         else if(count > 1)
16         printf("\n");    
17         int s[20][20] = {0};
18         //memset(s,0,sizeof(s));
19         scanf("%d",&c);
20         getchar();
21         for (int i = 0;i < r;i++ )
22         {
23             for (int j = 0;j < c;j++ )
24             {
25                 scanf("%c",&map[i][j]);
26             }
27             getchar();
28             
29         }
30         for (int i = 0;i < r;i++ )
31         {
32             for (int j = 0;j < c;j++ )
33             {
34                 if((i==0||j==0||map[i][j-1] == '*'||map[i-1][j] == '*') && map[i][j] != '*')
35                     s[i][j] = point++;
36             }
37         }
38         printf("puzzle #%d:\n",count++);
39         printf("Across\n");
40         for (int i = 0;i < r;i++ )
41         {
42             
43             for (int j = 0;j < c;j++ )
44             {
45                 int flag = 0;
46                 if(s[i][j] != 0)
47                 {
48                     flag = 1;
49                     printf("%3d.",s[i][j]);
50                     for (;j < c&&map[i][j] != '*';j++)
51                     printf("%c",map[i][j]);
52                 }
53                 if(flag)
54                 printf("\n");
55             }
56             
57             
58         }    
59         printf("Down\n");
60         for (int i = 0;i < r;i++ )
61         {
62             
63             for (int j = 0;j < c;j++ )
64             {
65                 int flag = 0;
66                 if(s[i][j] != 0)
67                 {
68                     flag = 1;
69                     printf("%3d.",s[i][j]);
70                     for(int x = i;x < r&&map[x][j] != '*';x++)
71                     {
72                         s[x][j] = 0;
73                         printf("%c",map[x][j]);
74                     }
75                 }
76                 if(flag)
77                 printf("\n");
78             }
79         
80             
81         }    
82         
83         
84     }
85     return 0;
86 }

 

posted @ 2018-02-07 15:20  Dicer  阅读(159)  评论(0编辑  收藏  举报