World Finals >> 1994-phoenix
Problem Link: UVA232 UVALive5171 POJ1888 crossword Answers. Basic Training level problem, programming in C language.
In a typical word puzzle, count the number of words.
Expands the boundaries of four directions to the grid. This simplifies the program logic so that the processing logic of the edge lattice is the same as the processing logic of the intermediate lattice. Makes it possible to determine whether the grid is the starting grid for the word, and the logic for calculating the word and column words is simple.
Another point is to be clear about the conditions of starting the grid, and how to calculate the ordinal number of the word (the condition of the ordinal increase).
program, the boundary is set to "*", the program logic is relatively concise.
The C language Program of AC is as follows:
/* UVA232 UVALive5171 POJ1888 Crossword Answers */#include <stdio.h> #define MAXN 10char grid[maxn+2][maxn+2];/* output line Word */void rowoutput (int no, int row, int col) {printf ("%3d.", no); while (Grid[row][col]! = ' * ') Putchar (grid[row][col++]); Putchar (' \ n ');} /* Output column word */void coloutput (int no, int row, int col) {printf ("%3d.", no); while (Grid[row][col]! = ' * ') Putchar (Grid[row++][col]); Putchar (' \ n ');} int main (void) {int R, C, caseno=0, Wcount, I, J; while (scanf ("%d", &r)! = EOF && r! = 0) {/* has been read, continue reading into row */scanf ("%d", &c); GetChar (); /* Read grid */for (i=1; i<=r; i++) {for (j=1; j<=c; j + +) Grid[i][j] = GetChar (); GetChar (); /* ' \ n '/}//Set boundary for (i=0; i<r+2; i++) {grid[i][0] = ' * '; GRID[I][C+1] = ' * '; } for (i=0; i<c+2; i++) {Grid[0][i] = ' * '; Grid[r+1][i] = ' * '; }/* Evaluates and outputs the result */if (++caseno > 1) printf ("\ n"); printf ("Puzzle #%d:\n", Caseno); /* line calculation and OUTPUT results */printf ("across\n"); Wcount = 0; For (I=1, i<=r; i++) {for (j=1; j<=c; j + +) if (grid[i][j]! = ' * ' && (grid[i-1][j] = = '*' || Grid[i][j-1] = = ' * ')) {wcount++; if (grid[i][j-1] = = ' * ') rowoutput (Wcount, I, J); }}/* column evaluates and outputs the result */printf ("down\n"); Wcount = 0; For (I=1, i<=r; i++) {for (j=1; j<=c; j + +) if (grid[i][j]! = ' * ' && (grid[i-1][j] = = '*' || Grid[i][j-1] = = ' * ')) {wcount++; if (grid[i-1][j] = = ' * ') coloutput (Wcount, I, J); }}} return 0;}
UVA232 UVALive5171 POJ1888 Crossword Answers