#include<stdio.h>
#include<string.h>
int main(){
int r,c,i,j,k,counter,number=0;
char str[10][10],digit1[10][10],digit2[10][10];
scanf("%d",&r);
while(r!=0){
counter=0;
memset(str,0,sizeof(str));
memset(digit1,0,sizeof(digit1));
memset(digit2,0,sizeof(digit2));
scanf("%d",&c);
getchar();
for(i=0;i<r;i++)
gets(str[i]);
for(i=0;i<r;i++)
for(j=0;j<c;j++){
if(str[i][j]!='*'){
if(i==0||j==0)
digit1[i][j]=++counter;
else if(str[i-1][j]=='*'||str[i][j-1]=='*')
digit1[i][j]=++counter;
}
}
counter=0;
for(i=0;i<r;i++)
for(j=0;j<c;j++){
if(str[i][j]!='*'){
if(i==0||j==0)
digit2[i][j]=++counter;
else if(str[i-1][j]=='*'||str[i][j-1]=='*')
digit2[i][j]=++counter;
}
}
printf("puzzle #%d:\n",++number);
//Across
printf("Across\n");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
if(digit1[i][j]>0){
printf(" %d.",digit1[i][j] );
while(str[i][j]!='*'&&j<c){
putchar(str[i][j]);
j++;
}
printf("\n");
}
}
}
//Down
printf("Down");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
k=i;
if(digit2[k][j]!=0){
printf("\n %d.",digit2[k][j]);
while(str[k][j]!='*'&&k<c){
putchar(str[k][j]);
digit2[k][j]=0;
k++;
}
}
}
}
printf("\n");
scanf("%d",&r);
}
return 0;
}
Uva232
最新推荐文章于 2021-12-29 09:52:52 发布