Answers to Crossword puzzles (UVa232)

Source: Internet
Author: User
Tags alphabetic character

The answer to a crossword puzzleTime limit:MS Memory Limit:0KB 64bit IO Format:%lld & %llu SubmitStatus

Description


Crossword Answers

A crossword puzzle consists of a rectangular grid of black and white squares and lists of definitions (or descriptions ).

One list of definitions is for ' words ' to being written left-to-right across white squares in the rows and the other list is For words to is written down white squares in the columns. (a word is A sequence of alphabetic characters.)

To solve a crossword puzzle, one writes the words corresponding to the definitions in the white squares of the grid.

The definitions correspond to the rectangular grid by means of sequential integers on ' eligible ' white squares. White squares and black squares immediately to the left or above them is ' eligible. White squares and no squares either immediately to the left or above is also ' eligible. No other squares is numbered. All of the squares on the first row is numbered.

The numbering starts with 1 and continues consecutively across white squares of the first row, then across the eligible WH Ite squares of the second row, then across the eligible white squares of the third row and so on across all of the rest of The rows of the puzzle. The picture below illustrates a rectangular crossword puzzle grid with appropriate numbering.

A ' across word for a definition are written on a sequence of white squares in a row starting on a numbered square that D OES not follow another white square in the same row.

The sequence of white squares for that word goes across the row of the numbered square, ending immediately before the next Black square in the row or in the rightmost square of the row.

A ' down ' word for a definition are written on a sequence of white squares in a column starting on a numbered square that D OES not follow another white square in the same column.

The sequence of white squares for so Word goes down the column of the numbered square, ending immediately before the NEX T Black square in the column or in the bottom square of the column.

Every white square in a correctly solved puzzle contains a letter.

You must write a program this takes several solved crossword puzzles as input and outputs the lists of across and down wor DS which constitute the solutions.

Input

Each puzzle solution in the input starts with a line containing the integers R and C (and), where r (the first number) is the number of rows in the puzzle and C (the second number) is the number of column S.

The r rows of input which follow each contain C characters (excluding the end-of-line) which describe th E solution. Each of those Ccharacters are an alphabetic character which are part of a word or the character "*", which indicat Es a black square.

The end of input is indicated by a line consisting of the "a" number 0.

Output

Output for each puzzle consists of a identifier for the puzzle (puzzle #1:, puzzle #2:, etc.) and the L Ist of across words followed by the list of down words. Words in each list must is output one-per-line in increasing order of the number of their corresponding definitions.

The heading for the list of across words is 'across'. The heading for the list of words are ' down '.

In the case where the lists is empty (all squares in the grid is black), the Across and down headings Should still appear.

Separate output for successive input puzzles by a blank line.

Sample Input

2 2at*o6 7aim*den*me*oneupon*toso*erin*sa*or*ies*dea0

Sample Output

Puzzle #1: Across  1.AT  3.ODown  1.A  2.TOpuzzle #2: Across  1.AIM  4.DEN 7.ME 8.ONE  9.UPON 11.TO 12.SO 13.ERIN 15.SA 17.OR 18.IES 19.DEADown  1.A  2.IMPOSE  3.MEO  4.DO  5.ENTIRE  6.NEON  9.US 10.NE 14.ROD 16.AS 18.I 20.A

Test instructions: Enter a grid of R row C columns, and Haig indicates that each white lattice is filled with a letter. If the left side of a white lattice or the upper adjacent position is not white (possibly Haig, the grid boundary may also be out), then the white lattice is called a starting lattice. First, all the starting grids are numbered from left to right, top to bottom, and .... Ask to find all the horizontal words. These words must start with a starting cell, extend right to the left of a black lattice, or to the far right of the entire grid. Finally, find out all the vertical words.


Code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set > #include <queue> #pragma comment (linker, "/stack:102400000,102400000") #define MAXN 105#define MAXN 2005# Define mod 1000000009#define INF 0x3f3f3f3f#define pi ACOs ( -1.0) #define EPS 1e-6typedef Long long ll;using namespace Std;s    truct st{int x, y; int r,c;}    St[111];char mp[12][12];int N,m;int Main () {int cas=0;        while (scanf ("%d", &n), N) {scanf ("%d", &m),//if (CAS) printf ("\ n"); for (int i=0;i<n;i++) scanf ("%s", Mp[i]);//for (int i=0;i<n;i++)//printf ("%s\n", Mp[i])        ;        int num=1;                for (int i=0;i<n;i++) {for (int j=0;j<m;j++) {if (mp[i][j]!= ' * ') {if (i-1) <0| | (j-1) <0| | mp[i-1][j]== ' * ' | |mp[i][j-1]== ' * ') {st[num].x=i;                        St[num].y=j; if ((j-1) <0| |  mp[i][j-1]== ' * ') st[num].r=1;                        else st[num].r=0; if ((i-1) <0| |  mp[i-1][j]== ' * ') st[num].c=1;                        else st[num].c=0;                    num++;        }}}} if (CAs) printf ("\ n");//printf ("num=%d\n", num);        printf ("Puzzle #%d:\nacross\n", ++cas);                for (int i=1;i<num;i++) {if (ST[I].R) {printf ("%3d.", i); for (int j=st[i].y;j<m;j++) {if (mp[st[i].x][j]== ' * ') break                    ;                printf ("%c", mp[st[i].x][j]);            } printf ("\ n");        }}//printf ("num=%d\n", num);        printf ("down\n");      for (int i=0;i<num;i++) {if (ST[I].C)      {printf ("%3d.", i); for (int j=st[i].x;j<n;j++) {if (mp[j][st[i].y]== ' * ') break                    ;                printf ("%c", mp[j][st[i].y]);            } printf ("\ n");    }}//printf ("\ n"); } return 0;}



Answers to Crossword puzzles (UVa232)

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.