Uva232 Crossword Answers

根据题意首先找出可以当作起始点的点,并用数字作顺序标记。

之后从这些起始点开始,向右开始搜寻字母组成单词,直至到边界或到黑块

之后依旧从这些起始点开始,向下开始搜寻字母组成单词,直至到边界或到黑块

其中注意输出格式如"  1.AT",题目并不是要求在数字前加2个空格,不难发现题目样例输出中有“ 19.DEA”,可以得知,题目的意思是:数字及数字前的空格总共占3个字符的位置

/*
    UvaOJ 232
    Emerald
    Sat 18 Apr, 2015
*/
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAXN = 10 + 2;
char puzzle[ MAXN ][ MAXN ];
int isStart[ MAXN ][ MAXN ];
//bool used[ MAXN ][ MAXN ];
int rows, cols, posCount;

const char BLACK_GRID = ‘*‘;

int isStarted( int i, int j ) { // judge whether the puzzle[i][j] is a starting point
    if( puzzle[i][j] == BLACK_GRID ) {
        return -1; // 这个
    }
    if( i-1<0 || j-1<0 ) {
        return ++posCount;
    }
    if( puzzle[i-1][j]==BLACK_GRID || puzzle[i][j-1]==BLACK_GRID ) {
        return ++posCount;
    }
    return -1;
}

void across( int x, int y ) { // whether can output a word
    if( ( y-1<0 || puzzle[x][y-1]==BLACK_GRID ) && puzzle[x][y]!=BLACK_GRID ) { // presention !!!
        printf( "%3d.", isStart[x][y] );
        while( y<cols && puzzle[x][y]!=BLACK_GRID ) {
            printf( "%c", puzzle[x][y++] );
        }
        printf("\n");
    }
}

void down( int x, int y ) { // whether can output a word
    if( ( x-1<0 || puzzle[x-1][y]==BLACK_GRID ) && puzzle[x][y]!=BLACK_GRID ) {
        printf( "%3d.", isStart[x][y] ); // presention !!!
        while( x<rows && puzzle[x][y]!=BLACK_GRID ) {
            printf( "%c", puzzle[x++][y] );
        }
        printf("\n");
    }
}

int main() {
    int i, j;
    int counter = 0;
    while( scanf( "%d", &rows )!=EOF && rows ) {
        scanf( "%d", &cols );
        posCount = 0;
        for( i=0; i<rows; i++ ) {
            getchar();
            for( j=0; j<cols; j++ ) {
                scanf( "%c", &puzzle[i][j] );
                isStart[i][j] = isStarted( i, j );
            }
        }
        if( counter ) {
            printf( "\n" );
        }
        printf( "puzzle #%d:\n", ++counter );
        /* --------Across---------- */
        printf( "Across\n" );
        for( i=0; i<rows; i++ ) {
            for( j=0; j<cols; j++ ) {
                across( i, j );
            }
        }
        /* --------Down---------- */
        printf( "Down\n" );
        for( i=0; i<rows; i++ ) {
            for( j=0; j<cols; j++ ) {
                down( i, j );
            }
        }
    }
    return 0;
}
时间: 2024-10-01 05:17:27

Uva232 Crossword Answers的相关文章

UVA232 UVALive5171 POJ1888 Crossword Answers

World Finals >> 1994 - Phoenix 问题链接:UVA232 UVALive5171 POJ1888 Crossword Answers.基础训练级的问题,用C语言编写程序. 典型单词谜题中,计算单词个数问题. 给网格扩充了四个方向的边界.这样可以简化程序逻辑,使得边缘格的处理逻辑与中间格的处理逻辑相同.使得判断网格是否为单词的开始网格条件统一:同时,计算行单词和列单词的逻辑也变得简单. 另外一点就是要明确单纯开始网格的条件,以及如何计算单词的序号(序号增加的条件).

poj 1888 Crossword Answers

Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 Description A crossword puzzle consists of a rectangular grid of black and white squares and two lists of definitions (or descriptions). One list of de

[算法竞赛入门经典] Crossword Answers ACM/ICPC World Finals 1994,UVa232

Description A crossword puzzle consists of a rectangular grid of black and white squares and two lists of definitions (or descriptions). One list of definitions is for "words" to be written left to right across white squares in the rows and the

UVa 232 - Crossword Answers

横排纵排找单词 先标记,再记录答案最后排序,排序时一定要对准首末位置 1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 #include <iomanip> 5 using namespace std; 6 struct T{ 7 int num; 8 char ans[15]; 9 }down[300],acr[300]; 10 int r,c,cnt1,cnt2,cnt

纵横字谜的答案 (UVa232)

纵横字谜的答案 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description  Crossword Answers  A crossword puzzle consists of a rectangular grid of black and white squares and two lists of definitions (or descriptions).

ACM今日学习总结(2015.08.16)

今日完成情况 UVa 第3章 数组与字符串 六道例题已全部完成. 例题3-1 272 - TEX Quotes 例题3-2 10082 - WERTYU 例题3-3 401 - Palindromes 例题3-4 340 - Master-Mind Hints 例题3-5 1583 - Digit Generator 例题3-6 1584 - Circular Sequence 十二道习题已完成(7道). 习题3-1 1585 - Score 习题3-2 1586 - Molar mass 习题

HDU 3038 - How Many Answers Are Wrong

Problem Description TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game. To begin with, TT should write down a sequence of intege

HDU3038 How Many Answers Are Wrong 【并查集】

How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3145 Accepted Submission(s): 1202 Problem Description TT and FF are - friends. Uh- very very good friends -__-b FF is a b

HDU - 3038 How Many Answers Are Wrong (带权并查集)

题意:n个数,m次询问,每次问区间a到b之间的和为s,问有几次冲突 思路:带权并查集的应用,[a, b]和为s,所以a-1与b就可以确定一次关系,通过计算与根的距离可以判断出询问的正确性 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 200010; int f[MAXN],a