纵横字谜的答案

来源:互联网 发布:摇号软件 编辑:程序博客网 时间:2024/04/27 13:44
Sample Input
2 2
AT
*O
6 7
AIM*DEN
*ME*ONE
UPON*TO
SO*ERIN
*SA*OR*
IES*DEA
0
Sample Output
puzzle #1:
Across
1.AT
3.O
Down
1.A
2.TO
puzzle #2:
Across
1.AIM
4.DEN
7.ME
8.ONE
9.UPON
11.TO
12.SO
13.ERIN
15.SA
17.OR
18.IES
19.DEA
Down
1.A
2.IMPOSE
3.MEO
4.DO
5.ENTIRE
6.NEON
9.US
10.NE
14.ROD
16.AS
18.I
20.A


#include<stdio.h>#include<string.h>#include<ctype.h>int main(){    int m, n, i, j, k, c=1, count, x, d=0;    char a[11][11], b[11][11];    while(scanf("%d",&m)!=EOF)    {        if(m==0) break;        count = 1;        memset(b, 0, sizeof(b));        scanf("%d", &n);        getchar();        for(i=0;i<m;i++)        {            for(j=0;j<n;j++)                scanf("%c", &a[i][j]);            getchar();        }        if(d==0)  d=1;        else  printf("\n");        printf("puzzle #%d:\nAcross\n",c++);        for(i=0;i<m;i++)            for(j=0;j<n;j++)                if((   (j>0&&a[i][j-1]=='*') || (j==0&&a[i][0]!='*') || (i>0&&a[i-1][j]=='*') || (i==0&&a[0][j]!='*')   )&&  a[i][j]!='*')                 {                    b[i][j]=count;                    count++;                }        for(i=0;i<m;i++)            for(j=0;j<n;j++)                if( (   (j==0&&a[i][0]!='*') || (j>0&&a[i][j-1]=='*')  ) &&a[i][j]!='*'  )                {                    printf("%3d.", b[i][j]);                    for(k=j;k<n&&a[i][k]!='*';k++)                        printf("%c", a[i][k]);                    printf("\n");                }        printf("Down\n");        for(i=0;i<m;i++)            for(j=0;j<n;j++)                if( (  (i>0&&a[i-1][j]=='*') || (i==0&&a[0][j]!='*')  )&&a[i][j]!='*'  )                {                    printf("%3d.", b[i][j]);                    for(k=i;k<m&&a[k][j]!='*';k++)                        printf("%c", a[k][j]);                    printf("\n");                }    }    return 0;}

原创粉丝点击