Question: The answer to the crossword is to enter a grid of R row C columns (1=<r,c<=10), and Haig uses the * number to denote a letter for each of the white lattice antennas. If there is no white space on the left side of a white lattice or in the upper adjacent position (possibly Haig, possibly a boundary), This is called the white lattice is a starting lattice
Each output must start from the initial grid to the ' * ' or end of the boundary
The idea of solving problems: two-dimensional array tags (initial lattice)
#include <stdio.h>
#include <string.h>
int main () {
Defining tables
Char puzzle[10][10];
Defining tags
int mark[10][10];
Line break Marker
int ct=0;
Ranks
int m,n;
Enter m and determine if it is entered correctly
while (scanf ("%d", &m) ==1) {
if (m==0) break;
Reset Zero
memset (Mark,0,sizeof (Mark));
Input n
scanf ("%d", &n);
int i=0;
Initialize Grid
while (I<M)
scanf ("%s", puzzle[i++]);
int j,p=1;
Traverse and Mark
for (int i=0;i<m;i++) {
for (j=0;j<n;j++) {
If ' * ' jump out of the loop and continue the loop
if (puzzle[i][j]== ' * ') continue;
Mark the initial grid
if (i==0| | j==0) mark[i][j]=p++;
else if (puzzle[i-1][j]== ' * ' | | puzzle[i][j-1]== ' * ') mark[i][j]=p++;
}
}
if (CT) printf ("\ n");
printf ("Puzzle #%d:\n", ++ct);
printf ("across\n");
Traverse output
for (int i=0;i<m;i++) {
for (int j=0;j<n;j++) {
Initial grid
if (mark[i][j]>0) {
printf ("%3d.", Mark[i][j]);
Output until ' * ' after the initial grid
while (j<n&&puzzle[i][j]!= ' * ') {
Putchar (puzzle[i][j++]);
}
Line break
printf ("\ n");
}
}
}
printf ("down\n");
for (int j=0;j<n;j++) {
for (int i=0;i<m;i++) {
Initial grid
if (mark[i][j]>0) {
printf ("%3d.", Mark[i][j]);
Output until ' * ' after the initial grid
while (i<m&&puzzle[i][j]!= ' * ') {
Putchar (Puzzle[i++][j]);
}
Line break
printf ("\ n");
}
}
}
}
return 0;
}
C + + Crossword puzzle