I feel this question is to understand his main output, can be found in his output is from small to large order to the number, and each letter is available only once, so long as properly initialized, the array deposit to open a number, again using a deposit case, it is ok
anyway, two-step, to find the starting point,
the output cross word, after word of the output column
( Caution is empty lines between the two groups to be oh )
#include <bits/stdc++.h>
using namespace std;
int main()
{
int r,l,wen = 0; // wen表示问题个数
while(scanf("%d",&r)==1 && r)
{
scanf("%d",&l);
int ge = 0,b[12][12]={0},c[12][12]={0};
char a[12][12]={'\0'};
for (int i = 0; i < r;i++)
scanf("%s",a[i]); //读入 r行
//起始寻找
for (int i = 0; i < r;i++)
for (int j = 0; j < l;j++)
{ //上 左
if((i==0||j==0||a[i-1][j]=='*'||a[i][j-1]=='*')&&a[i][j]!='*')
b[i][j] = ++ge;;
}
//暴力找数
if(wen) printf("\n");
printf("puzzle #%d:\n",++wen);
printf("Across\n");
for (int i = 0; i < r; i++)
for (int j = 0; j < l; j++)
{
if(b[i][j]&&!c[i][j]) // 找的数既要是起始点,有要没用过
{
printf("%3d.",b[i][j]);
int x = i,y =j;
while(x<r && y<l && a[x][y]!='*')
{
putchar(a[x][y]);
c[x][y] = 1;
y++;
}
printf("\n");
}
}//across
printf("Down\n");
memset(c,0,sizeof(c)); // 刚才用了先清空
for (int i = 0; i < r; i++)
for (int j = 0; j < l; j++)
{
if(b[i][j]&&!c[i][j])
{
printf("%3d.",b[i][j]);
int x = i,y =j;
while(x<r && y<l && a[x][y]!='*')
{
putchar(a[x][y]);
c[x][y] = 1;
x++;
}
printf("\n");
}
}
}
return 0;
}