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. [译]FastClick: native-like tapping for touch apps

    原文地址:http://labs.ft.com/2011/08/fastclick-native-like-tapping-for-touch-apps/ 这篇文章是一篇老文了,现在才看到,真是落后啊 ...

  2. LVS + KEEPAlived 配置 DIR模式

    1 .1 Lvs LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目 ...

  3. IOS UINavigationController 导航控制器

    /** 导航控制器掌握: 1.创建导航控制器 UINavigationController *nav = [[UINavigationController alloc] initWithRootVie ...

  4. 在不知道json格式的情况下如何使用cjson进行解析

    假设我们有一个json字符串,但是我们不知道这个json的组织方式,那么如何进行解析呢,下面就给一个小例子. 1.我们的json串如下: { "aStr": "aaaaa ...

  5. 分模块创建maven项目(二)

    1.新建Parent项目,MavenProject 2.新建子模块项目,MavenProject 右击项目名 --> NEW --> other 结果,在parent上运行会打出两个包,一 ...

  6. 终于懂浏览器里面的cookies和session了

    在PHP开发中对比起Cookie,session 是存储在服务器端的会话,相对安全,并且不像 Cookie 那样有存储长度限制: (Php.Asp.Jsp)---: cookie(客户端)界面没有刷新 ...

  7. iOS 中实现功能引导页面

    // //  guideView.h //  07-功能引导-李洪强 // //  Created by vic fan on 16/1/4. //  Copyright © 2016年 李洪强. A ...

  8. JS中的window.setTimeout()详解

    相关用法: setTimeout (表达式,延时时间)setInterval (表达式,交互时间)其中延时时间/交互时间是以豪秒为单位的(1000ms=1s) setTimeout 在执行时,是在载入 ...

  9. tab左右箭头切换

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

  10. 第一章 开始编写第一个jsp

    第一章 搭好框架,需要tomcat服务器和jdk. JSP是Java Server Page的缩写,现在先让我们编写一个简单的jsp页面,看看jsp究竟能干什么? <%=new java.uti ...