#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
//freopen("input.txt","r",stdin);
int r,c,T=0,i,j,k,m,n;
while(cin>>r)
{
if(r==0)
break;
T++;
cin>>c;
char a[10][10];
int w[10][10]={0};
int x[10][10]={0};
int y[10][10]={0};
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
cin>>a[i][j];
if(a[i][j]=='*')
{
x[i][j]=-1;
y[i][j]=-1;
}
}
k=0;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
if((j-1<0||a[i][j-1]=='*'||i-1<0||a[i-1][j]=='*')&&a[i][j]!='*')
w[i][j]=++k;
if((j-1<0||a[i][j-1]=='*')&&a[i][j]!='*')
x[i][j]=1;
if((i-1<0||a[i-1][j]=='*')&&a[i][j]!='*')
y[i][j]=1;
}
if(T!=1)
cout<<endl;
cout<<"puzzle #"<<T<<':'<<endl;
cout<<"Across"<<endl;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
if(x[i][j]<=0)
continue;
else
{
printf("%3d.",w[i][j]);
while(x[i][j]>=0&&j<c)
cout<<a[i][j++];
cout<<endl;
}
}
cout<<"Down"<<endl;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
if(y[i][j]<=0)
continue;
else
{
printf("%3d.",w[i][j]);
m=i,n=j;
while(y[m][n]>=0&&m<r)
cout<<a[m++][n];
cout<<endl;
}
}
}
return 0;
}
UVA - 232 Crossword Answers
最新推荐文章于 2022-08-23 16:45:00 发布