码迷,mamicode.com
首页 > 其他好文 > 详细

UVA232-纵横字谜的答案

时间:2020-02-04 15:47:18      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:color   注意   ack   一个   eof   mem   https   ble   sizeof   

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

分析:在输入的同时用序号对起始格标记,然后按照输出要求输出即可。(注意:本题最后一个样例末尾没有空行)

 1 #include <stdio.h>
 2 #include <string.h>
 3 int main(void){
 4     int l,w;
 5     char c[11][13];
 6     int f[11][13];
 7     int k=0;
 8     while(scanf("%d",&l)==1&&l){
 9             int t=1;
10         scanf("%d",&w);
11         memset(c,\0,sizeof(c));
12         memset(f,0,sizeof(f));
13         for(int i=1;i<=l;i++){
14             for(int j=1;j<=w;j++){
15                 scanf("%c",&c[i][j]);
16                 if(c[i][j]== ||c[i][j]==\n)
17                 scanf("%c",&c[i][j]);
18                 if((i-1==0||j-1==0)&&c[i][j]!=*){
19                     f[i][j]=t;
20                     t++;
21                 }
22                 else if((c[i-1][j]==*||c[i][j-1]==*)&&f[i][j]==0&&c[i][j]!=*){
23                     f[i][j]=t;
24                     t++;
25                 }
26             }
27         }
28         if(k)printf("\n");
29         printf("puzzle #%d:\nAcross\n",++k);
30         for(int i=1;i<=l;i++){
31             for(int j=1;j<=w;){
32                 if(f[i][j]!=0){
33                     printf("%3d.",f[i][j]);
34                     while(c[i][j]!=*&&j<=w){
35                         printf("%c",c[i][j]);
36                         j++;
37                     }
38                     printf("\n");
39                 }
40                 j++;
41             }
42         }
43         printf("Down\n");
44         for(int i=1;i<=l;i++){
45             for(int j=1;j<=w;j++){
46                 if(f[i][j]!=0&&(c[i-1][j]==*||i-1==0)){
47                     int h=i;
48                     printf("%3d.",f[i][j]);
49                     while(c[h][j]!=*&&h<=l){
50                         printf("%c",c[h][j]);
51                         h++;
52                     }
53                     printf("\n");
54                 }
55             }
56         }
57     }
58     return 0;
59 }

 

UVA232-纵横字谜的答案

标签:color   注意   ack   一个   eof   mem   https   ble   sizeof   

原文地址:https://www.cnblogs.com/yanying7/p/12259488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!