UVa232のクロスワードの解答(クロスワードパズルの答え)

クロスワードパズルは、定義の.Oneリストは行および他のリストに白四角横切って左から右へ書き込まれる\単語」のためである長方形の黒と白の正方形のグリッドおよび定義(または記述)の二つのリストから成り列の白い四角を書き留めする単語(単語は、アルファベット文字のシーケンスである。)クロスワードパズルを解決するために、一方がgrid.The定義の白四角で定義に対応する単語が矩形に対応する書き込み無正方形のいずれかのすぐ上の左またはホワイト正方形「のすぐ左に彼らは資格を\しているorabove。黒四角と白のsquares.Whiteの広場」\資格のシーケンシャル整数によるグリッドも\対象となります。」他の四角に番号をされていません。1行目の正方形のすべてが番号付けされます。
2行目の対象白四角横切って、第3行の適格白い四角を横切るなどパズルの行の残りのすべてにわたって。下図は同じrow.Theに別の白い正方形に従わない番号の正方形から始まる行の白の正方形の配列に書き込まれている定義するワード「を横切る適切なnumbering.An \有する矩形クロスワードパズルのグリッドを示しますその単語の白い四角のシーケンスは、白の順に書かれている行または定義については、単語「ダウンrow.A \の右端の四角内の次の黒い四角の直前に終了し、番号の正方形の列を横切りますカラム内の正方形は、同じ列内の別の白い四角に従わない番号が広場に始まります。

 

Input
Each puzzle solution in the input starts with a line containing two integers r and c (1 r 10 and 1 c 10), where r (the first number) is the number of rows in the puzzle and c (the second number)
is the number of columns.The r rows of input which follow each contain c characters (excluding the end-of-line) which describe the solution. Each of those c characters is an alphabetic character which is part of a word or the
character ‘*’, which indicates a black square.The end of input is indicated by a line consisting of the single number ‘0’.
Output
Output for each puzzle consists of an identifier for the puzzle (puzzle #1:, puzzle #2:, etc.) and the list of across words followed by the list of down words. Words in each list must be 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 down words is ‘Down’.In the case where the lists are empty (all squares in the grid are black), the ‘Across’ and ‘Down
headings should still appear.Separate output for successive input puzzles by a blank line.
Sample Input
2 2
AT
*O
6 7
AIM*DEN
*ME*ONE
UPON*TO
SO*ERIN
*SA*OR*
IES*DEA
0
Sample Output
puzzle #1:
Across
1.AT
3.O
Down
1.A
2.TO
puzzle #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.DEA
Down
1.A
2.IMPOSE
3.MEO
4.DO
5.ENTIRE
6.NEON
9.US
10.NE
14.ROD
16.AS
18.I
20.A

 

解答:

ps(输出格式有误)

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char map[20][20];
int n=0,t=0,num[20][20],r,c;
int can(int x,int y)
{
    if(map[x][y]=='*') return 0;
    if(x==1||y==1) return 1;
    if(map[x-1][y]!='*'&&map[x][y-1]!='*')return 0;
    return 1;
}
void across(int x,int y)
{
    printf("  %d.",num[x][y]);
    while(map[x][y]!='*'&&y<=c)
    {
        cout<<map[x][y];
        y++;
    }
    cout<<endl;
    return;
}
void down(int x,int y)
{
    printf("  %d.",num[x][y]);
    while(map[x][y]!='*'&&x<=r)
    {
        cout<<map[x][y];
        x++;
    }
    cout<<endl;
    return;
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(1)
    {
        n++;
        t=0;
        scanf("%d",&r);
        if(r==0)
        {
            printf("\n");
            return 0;
        }
        scanf("%d",&c);
        map[0][0]=getchar();
        for(int i=1;i<=r;i++)
        {
            for(int j=1;j<=c;j++)
            {
                map[i][j]=getchar();
            }
            map[0][0]=getchar();    
        }
        for(int i=1;i<=r;i++)
        {
            for(int j=1;j<=c;j++)
            {
                if(can(i,j))
                {
                    t++;
                    num[i][j]=t;
                }
            }    
        }
        printf("puzzle #%d:\n",n);
        printf("Across\n");
        for(int i=1;i<=r;i++)
        {
            for(int j=1;j<=c;j++)
            {
                if(j==1&map[i][j]!='*')
                {
                    across(i,j);
                    continue;
                }
                if(map[i][j]=='*') continue;
                if(map[i][j-1]=='*') across(i,j);
            }
        }
        printf("Down\n");
        for(int i=1;i<=r;i++)
        {
            for(int j=1;j<=c;j++)
            {
                if(i==1&map[i][j]!='*')
                {
                    down(i,j);
                    continue;
                }
                if(map[i][j]=='*') continue;
                if(map[i-1][j]=='*') down(i,j);
            }
        }
        printf("\n");
    }
}

おすすめ

転載: www.cnblogs.com/satans/p/11111296.html