题目链接: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. 为什么新建的管理员账号权限没有Administrator大?

    Administrator是超级管理员,UAC不用确认,跟关了一样. 新建隶属于administrator组的用户,可以关掉UAC. 控制面板>系统和安全>操作中心>更改用户帐户控制 ...

  2. java.lang.NoClassDefFoundError 异常

    在项目实施过程中,当访问某一个功能时,出现异常为  java.lang.NoClassDefFoundError  com/xxx/yyy/Zzzz > ,检查发现这个类实际已经存在于应用服务器 ...

  3. iOS UILabel UITextView UIButton 等等显示文本行间距

    iOS UILabel  UITextView UIButton 等等显示文本行间距都用如下方法 NSMutableParagraphStyle *paragraphStyle = [[NSMutab ...

  4. pyqt cvs保存

    # -*- coding: utf-8 -*-__author__ = 'Administrator'import sys, csvfrom PyQt4 import QtGui, QtCore cl ...

  5. 找工作笔试面试那些事儿(10)---SQL语句总结

    SQL语句中常用关键词及其解释如下: 1)SELECT 将资料从数据库中的表格内选出,两个关键字:从 (FROM) 数据库中的表格内选出 (SELECT).语法为 SELECT "栏位名&q ...

  6. 利用JConsole工具监控java程序内存和JVM

    一.找到java应用程序对应的进程PI 性能测试应用程序访问地址:http://192.168.29.218:7070/training/ 部署的应用服务器为tomcat6.028 启动tomcat服 ...

  7. linux 服务器更主板后无法识别网卡处理过程

    linux 服务器更主板后无法识别网卡处理过程   服务器故障报修,主板坏,更换主板后无法识别网卡,ifconfig 查看只显示:lo loopback 127.0.0.1. 系统加载网卡驱动后会去读 ...

  8. oracle监听

    启动实例时,监听程序进程会建立一个指向Oracle DB 的通信路径.随后,监听程序可接受数据库连接请求.使用监听程序控制实用程序可控制监听程序.使用lsnrctl,可以:• 启动监听程序• 停止监听 ...

  9. javascript紧接上一张for循环的问题,我自己的理解

    这类问题,通常都是在for循环里,根据i的变化作为dom的下标来作当前dom的点击事件, 预期是,每个点击事件都对应相应的i下标,但是问题是,每次点击的都是最后一次节点的dom. 原因就是其实我们作点 ...

  10. Java ------------获取不会重复的随机数

    import java.util.UUID; public class UTest {    public static void main(String[] args) { //UUID通过rand ...