UVA232 UVALive5171 POJ1888 Crossword Answers

Source: Internet
Author: User

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

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.