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 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 (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.

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

  这是一道字符串模拟题。给你一个字符矩阵,让你水平读,竖直读。遇到'*'或者换行,就输出读取的字符串,至于编号,则是第一行和第一列非‘*’的都要标号,其他的若该字符不是‘*’并且其前一个或是上一个字符若为‘*’则将其编号。

下面是我的代码:

 #include <iostream>
#include <iomanip>
using namespace std;
char ch[][];
int ch1[][]; int main()
{
int r,c,i,j,k,m,puzzle=;
while(cin>>r && r)
{
cin>>c;
memset(ch1,,sizeof(ch1));
for(i=; i<r; i++)
for(j=; j<c; j++)
cin>>ch[i][j];
m = ;
for(i=; i<r; i++) //对字符进行编号
for(j=; j<c; j++)
{
if(i== || j==)
{
if(ch[i][j] != '*')
ch1[i][j] = m++;
}
else
{
if(ch[i][j] != '*')
if(ch[i-][j]=='*' || ch[i][j-]=='*')
ch1[i][j] = m++;
}
}
cout<<"puzzle #"<<puzzle++<<":"<<endl;
cout<<"Across"<<endl;
{
for(i=; i<r; i++)
for(j=; j<c; j++)
{
if(ch[i][j]!='*')
{
cout<<setw()<<ch1[i][j]<<"."<<ch[i][j];
j++;
while(j<c && ch[i][j]!='*')
cout<<ch[i][j++];
j--;
cout<<endl;
}
}
}
cout<<"Down"<<endl;
{
for(i=; i<r; i++)
{ for(j=; j<c; j++)
{
k=i;
if(ch[k][j]!='*')
{
cout<<setw()<<ch1[k][j]<<"."<<ch[k][j];
ch[k][j] = '*';
k++;
while(k<r && ch[k][j]!='*')
{
cout<<ch[k][j];
ch[k][j] = '*';
k++;
}
k--;
cout<<endl;
}
}
}
}
cout<<endl;
}
return ;
}

poj 1888 Crossword Answers 模拟题的更多相关文章

  1. POJ - 1835 宇航员(模拟题)

    问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示: 现对六个方向分别标 ...

  2. POJ 2348 Euclid Game (模拟题)

    Euclid's Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7942   Accepted: 3227 Des ...

  3. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  4. POJ 3393 Lucky and Good Months by Gregorian Calendar 模拟题

    题目:http://poj.org/problem?id=3393 不多说了,简单模拟题,因为粗心写错了两个字母,导致错了N遍,模拟还是一贯的恶心,代码实在不想优化了,写的难看了点.. #includ ...

  5. POJ 模拟题集合

    http://www.cppblog.com/Uriel/articles/101592.html 感觉这个暑假没有去年有激情啊,,,还没到状态就已经块上学了,,, 真是弱暴了,,,找几道模拟题刷刷. ...

  6. POJ 3923 Ugly Windows(——考察思维缜密性的模拟题)

    题目链接: http://poj.org/problem?id=3923 题意描述: 输入一个n*m的屏幕 该屏幕内有至少一个对话框(每个对话框都有对应的字母表示) 判断并输出该屏幕内处于最表层的对话 ...

  7. POJ 1008 简单模拟题

    e.... 虽然这是一道灰常简单的模拟题.但是米做的时候没有读懂第二个日历的计时方法.然后捏.敲完之后华丽的WA了进一个点.坑点就在一年的最后一天你是该输出本年的.e ...但是我好想并没有..看di ...

  8. UVa232.Crossword Answers

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

  9. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

随机推荐

  1. golang github.com/go-sql-driver/mysql 遇到的数据库,设置库设计不合理的解决方法

    golang github.com/go-sql-driver/mysql 遇到的数据库,设置库设计不合理的解决方法,查询中报了以下这个错 Scan error on column index 2: ...

  2. IIS7 + mysql + php + wordPress 在win7下部署

    最近在玩WordPress.wiki等开源平台的站点部署.通过一下实践和资料学习,为了以后少走弯路,觉得有必要把这个过程记录下来. 用到的东西: IIS服务: mysql; php; wordpres ...

  3. B-树的插入、查找、删除

    转自:http://blog.163.com/zhoumhan_0351/blog/static/39954227200910231032917/ 前面讨论的查找都是内查询算法,被查询的数据都在内存. ...

  4. unity3d插件Daikon Forge GUI 中文教程3-基础控件Button和Sprite的使用

    2.2添加一个按钮Button 来看看特有的属性:Button Properties Data 显示的文本 Behavior 中的几个: Aoto Size 选中时就是按钮的背景会根据Data中的文本 ...

  5. 图片懒加载插件lazyload使用方法

    图片懒加载插件lazyload使用方法 一.如何使用: Lazy Load 依赖于 jQuery.引入文件 <script type="text/javascript" sr ...

  6. Another app is currently holding the yum lock; waiting for it to exit...

    刚安装完虚拟机,用xshell连接上linux后,安装程序时一直出现这个信息Another app is currently holding the yum lock; waiting for it ...

  7. powerdesigner的基本使用转载

    http://www.blogjava.net/wangdetian168/archive/2011/04/07/347847.html

  8. MySQL Server-id踩到的坑

    最近踩到一个说大不大,说小不小的坑,在此分享出来给各位同学.事情是这样的,线上有2台服务器,1主1从.A -> B,B服务器从A服务器同步数据.每天使用xtrabackup在B服务器上面进行全备 ...

  9. c++ basic 整理1

    //c++类 初始化 与 初始赋值 //C++规定 对象的 成员变量 初始化 动作发生 在进入 构造函数本体 之前 . 在构造函数内 成员变量赋值都属于 赋值 . class People { pub ...

  10. css - float浮动模块的高度问题 解决方案

    当一个Div中的子元素都是浮动元素时,该div是没有高度的.通常会带来很多困扰,解决方案如下: 低版本统配兼容: overflow: hidden; 下面是不支持低配浏览器,而且似乎该效果对 P 标签 ...