题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=168

(该题目同POJ 1888)

13832879 232 Crossword Answers Accepted C++ 0.279 2014-07-04 13:47:00
13832817 232 Crossword Answers Runtime error C++11 0.000 2014-07-04 13:30:54
13832786 232 Crossword Answers Runtime error C++ 0.000 2014-07-04 13:24:03
13832776 232 Crossword Answers Runtime error C++ 0.000 2014-07-04 13:21:02

 Crossword Answers 

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 other list is for words to be 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 on the white squares of the grid.

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

The numbering starts with 1 and continues consecutively across white squares of the first row, then across the eligible white 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.

An ``across" word for a definition is written on a sequence of white squares in a row starting on a numbered square that does 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 is written on a sequence of white squares in a column starting on a numbered square that does not follow another white square in the same column.

The sequence of white squares for that word goes down the column of the numbered square, ending immediately before the next 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 that takes several solved crossword puzzles as input and outputs the lists of across and down words which constitute the solutions.

Input

Each puzzle solution in the input starts with a line containing two 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 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

解题思路:纯粹字符串乱搞题。开始由于输出时候遍历越界使劲的RE,在不严谨的POJ上居然没有RE,直接AC了,让我好无语。看来是g++和C++的编译环境差异,以后有机会去了解一下两者的区别。越说越想看CSAPP呃。

 #include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std; bool cmp(pair<int, string> a, pair<int, string> b) {
return a.first < b.first;
} int main() {
char Map[][];
int Mapf[][];
int x, y, cnt = ; while(cin >> x) {
if(x) cin >> y;
else break;
for(int i = ; i < ; i++) {
for(int j = ; j < ; j++) {
Map[i][j] = '*'; }
}
memset(Mapf, , sizeof(Mapf));
pair<int, string> p[];
int cur = ; for(int i = ; i <= x; i++) {
for(int j = ; j <= y; j++) {
cin >> Map[i][j];
if(Map[i][j] == '*') {
Mapf[i][j] = -;
} else {
if(i - < || j - < || Map[i - ][j] == '*' || Map[i][j - ] == '*') Mapf[i][j] = ++cur;
else Mapf[i][j] = -;
}
}
}
/*for(int i = 1; i <= x; i++) {
for(int j = 1; j <= y; j++) {
cout << Mapf[i][j] << " ";
}
cout << endl;
}*/
if(cnt) cout << endl;
int last = ;
printf("puzzle #%d:\n", ++cnt);
cout << "Across" << endl;
for(int i = ; i < ; i++) {
string str = "";
for(int j = ; j < ; j++) {
if(Map[i][j] != '*') {
if(str == "") last = Mapf[i][j];
str += Map[i][j];
} else {
if(str != "") {//cout << " " << last << "." << str << endl;
printf("%3d.", last);
cout << str << endl;
}
str = "";
} }
} cout << "Down" << endl;
int pcu = ;
for(int j = ; j < ; j++) {
string str = "";
for(int i = ; i < ; i++) {
if(Map[i][j] != '*') {
if(str == "") last = Mapf[i][j];
str += Map[i][j];
} else {
if(str != "") {
p[pcu].first = last;
p[pcu++].second = str;
//cout << " " << last << "." << str << endl;
str = "";
}
} }
}
sort(p, p + pcu, cmp);
for(int i = ; i < pcu; i++) {
printf("%3d.", p[i].first);
cout << p[i].second<<endl;
}
} return ;
}


UVa232.Crossword Answers的更多相关文章

  1. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  2. UVa 232 Crossword Answers

     Crossword Answers  A crossword puzzle consists of a rectangular grid of black and white squares and ...

  3. 紫书第三章训练1 D - Crossword Answers

    A crossword puzzle consists of a rectangular grid of black and white squares and two lists of defini ...

  4. Crossword Answers -------行与列按序输出

    题目链接:https://vjudge.net/problem/UVA-232#author=0 题意:关键句:The de nitions correspond to the rectangular ...

  5. Crossword Answers UVA - 232

    题目大意 感觉挺水的一道题.找出左面右面不存在或者是黑色的格子的白各,然后编号输出一横向单词和竖向单词(具体看原题) 解析 ①找出各个格子的编号 ②对每个节点搜索一下 ③输出的时候注意最后一个数据后面 ...

  6. 【习题 3-6 UVA - 232】Crossword Answers

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟题.注意场宽为3 [代码] #include <bits/stdc++.h> using namespace std ...

  7. [刷题]算法竞赛入门经典 3-4/UVa455 3-5/UVa227 3-6/UVa232

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa455:Periodic Strings 代码: //UVa455 #inclu ...

  8. Uva 232 一个换行WA 了四次

    由于UVA OJ上没有Wrong anwser,搞的多花了好长时间去测试程序,之前一直以为改OJ有WA,后来网上一搜才知道没有WA,哎哎浪费了好长时间.此博客用来记录自己的粗心大意. 链接地址:htt ...

  9. HDU3038 How Many Answers Are Wrong[带权并查集]

    How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

随机推荐

  1. 20个最强的基于浏览器的在线代码编辑器 - OPEN资讯

    20个最强的基于浏览器的在线代码编辑器 - OPEN资讯 20个最强的基于浏览器的在线代码编辑器

  2. c指针点滴4-指针的值

    #include <stdio.h> #include <stdlib.h> void main() { ; int *p = &num; //double *p1 = ...

  3. Spring初学(一)

    Spring核心机制:依赖注入 依赖注入简单的理解就是 由Spring负责对model进行设置,而非由controller直接设置. 通过依赖注入,javaEE各种组件可以解耦. 依赖注入(Depen ...

  4. Html中版权符号的字体选择问题(如何让版权符号更美观)

    一.发现问题 ©是html的中版权的符号,但是字体选择的不对会带来一些问题.如果是宋体,这个符号显示的就是很奇怪的一个符号. 二.解决问题 复制代码 代码如下: <span style=&quo ...

  5. ASE中的主要数据库

    Adaptive Server包括多种类型数据库: 必需数据库. “附加功能”数据库 .例子数据库 .应用数据库 1.必需数据库 master 数据库包含系统表,这些系统表中存储的数据被用来管理,有 ...

  6. VCS仿真生成fsdb文件(Verilog)

    VCS仿真生成fsdb文件(Verilog) 一.环境 Linux 平台 csh环境 VCS 64bit Verdi3 二.开始仿真 1. 联合仿真环境配置 a.在testbench中加入如下语句: ...

  7. 页面全部加载完毕和页面dom树加载完毕

    dom树加载完毕 $(document).ready()//原生写法document.ready = function (callback) {            ///兼容FF,Google   ...

  8. 巧记--Css选择器

    love  ------>   hate 即: a:link   -->  a:visited  -->  a:hover   -->  a:active a:link     ...

  9. Jquery:Jquery中的事件<一>

    由于今天有一个比较重要的面试,所以昨天晚上对以前做的一些项目做了一下总结,直接导致昨天的学习笔记断更了,哎,计划永远赶不上变化啊!今天学习了Jquery中是事件,就此做一个笔记,便于日后复习. 一.加 ...

  10. ORACLE函数详解【weber出品】

    一.什么是函数 一个函数: 1. 是命名的PL/SQL块,必须返回一个值 2. 可以存储到数据库中重复执行 3. 可以作为表达式的一部分或者提供一个参数值 二.创建函数的语法 必须至少有一个返回值,创 ...