//
看清楚题意再敲还是 原来的blog上的
//
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
char Get_array(char str[101][101],int row)
{
int i;
for(i=0;i<row;i++)
{
gets(str[i]);
}
}
int main()
{
char str[101][101],Across[1001][1001],Down[1001][1001];
int row,line;
int count;
int x,y;
int m,n,p,q;
int i,j,I,J;
int Begin_x[1000],Begin_y[1000];
int res;
//res的作用是避免同时加。说不太清楚,写的时候就知道了。
int num=0;
while(1)
{
x=0;y=0;
m=-1,n=0,p=-1,q=0;
count=0;
num++;
scanf("%d",&row);
if(row==0)
return 0;
scanf("%d",&line);
getchar();
Get_array(str,row);
//二维数组输入
for(I=0;I<row;I++)
{
for(J=0;J<line;J++)
{
res=0;
if(J==0&&str[I][0]!='*')
{
res=1;
m++;
count++;
Begin_x[x]=count;
x++;
i=I;j=J;
while(str[i][j]!='*'&&j<line)
{
Across[m][n]=str[i][j];
n++;
j++;
}
n=0;
}
else if(str[I][J-1]=='*'&&str[I][J]!='*')
{
res=1;
m++;
count++;
Begin_x[x]=count;
x++;
i=I;j=J;
while(str[i][j]!='*'&&j<line)
{
Across[m][n]=str[i][j];
n++;
j++;
}
n=0;
}
if(I==0&&str[0][J]!='*')
{
p++;
if(!res)
count++;
Begin_y[y]=count;
y++;
i=I;j=J;
while(str[i][J]!='*'&&i<row)
{
Down[p][q]=str[i][J];
q++;
i++;
}
q=0;
}
else if(str[I-1][J]=='*'&&str[I][J]!='*')
{
p++;
if(!res)
count++;
Begin_y[y]=count;
y++;
i=I;j=J;
while(str[i][j]!='*'&&i<row)
{
Down[p][q]=str[i][J];
q++;
i++;
}
q=0;
}
}
}
if(num!=1)
{
printf("\n");
}
printf("puzzle #%d:\n",num);
printf("Across\n");
for(i=0,j=0;i<=m;i++)
{
printf("%3d.",Begin_x[j]);
j++;
puts(Across[i]);
}
printf("Down\n");
for(i=0,j=0;i<=p;i++)
{
printf("%3d.",Begin_y[i]);
puts(Down[i]);
}
memset(str,0,sizeof(str));
memset(Across,0,sizeof(Across));
memset(Down,0,sizeof(Down));
memset(Begin_x,0,sizeof(Begin_x));
memset(Begin_y,0,sizeof(Begin_y));
}
return 0;
}