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. Js C# 实现跨域访问数据

    使用项目一的js调用项目二的数据 1.项目一 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta ...

  2. 深入浅出 - Android系统移植与平台开发(七)- 初识HAL

    作者:唐老师,华清远见嵌入式学院讲师. 1. HAL的module与stub HAL(Hardware AbstractLayer)硬件抽象层是Google开发的Android系统里上层应用对底层硬件 ...

  3. ASP.NET生成静态方法

    CMS系统如果新闻多了,全部生成静态的话.不现实,而且占用空间比较大.那么只生成网站首页是必须的了,下面列出JCMS首页生成静态的方法.换一种思路其实更简单. 当点击生成首页静态的时候.去获取动态首页 ...

  4. webservice的Axis2入门教程java版

    本文转自百度文库 Axis2是一套崭新的WebService引擎,该版本是对Axis1.x重新设计的产物.Axis2不仅支持SOAP1.1和SOAP1.2,还集成了非常流行的REST WebServi ...

  5. OpenStack 二次开发环境和开发工具的选择

    OpenStack网上安装教程很多,就不介绍安装了,OpenStack所有组件都安装完后,dashboard web里面进行一些操作,没有报错或提示权限问题,就可以直接下载pycharm或者eclip ...

  6. 用CSS设置Table的细边框的最好用的方法

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. Android 图片轮播(最简单的)

    布局文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android ...

  8. 提交form表单不刷新页面案列

    提交form表单不刷新页面其实很简单的,这里拿上传图片来举列,大家有什么其它的方法也欢迎留言告知与我 <form action="" method="post&qu ...

  9. 流式布局&固定宽度&响应式&rem

    我们现在在切页面布局的使用常用的单位是px,这是一个绝对单位,web app的屏幕适配有很多中做法,例如:流式布局.限死宽度,还有就是通过响应式来做,但是这些方案都不是最佳的解决方法. 1.流式布局: ...

  10. php课程---初学练习

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...