C + + Crossword puzzle

Source: Internet
Author: User

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&LT;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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.