poj 1888 Crossword Answers 模拟题
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 869 | Accepted: 405 |
Description
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
Output
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 模拟题的更多相关文章
- POJ - 1835 宇航员(模拟题)
问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示: 现对六个方向分别标 ...
- POJ 2348 Euclid Game (模拟题)
Euclid's Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7942 Accepted: 3227 Des ...
- poj 1008:Maya Calendar(模拟题,玛雅日历转换)
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64795 Accepted: 19978 D ...
- POJ 3393 Lucky and Good Months by Gregorian Calendar 模拟题
题目:http://poj.org/problem?id=3393 不多说了,简单模拟题,因为粗心写错了两个字母,导致错了N遍,模拟还是一贯的恶心,代码实在不想优化了,写的难看了点.. #includ ...
- POJ 模拟题集合
http://www.cppblog.com/Uriel/articles/101592.html 感觉这个暑假没有去年有激情啊,,,还没到状态就已经块上学了,,, 真是弱暴了,,,找几道模拟题刷刷. ...
- POJ 3923 Ugly Windows(——考察思维缜密性的模拟题)
题目链接: http://poj.org/problem?id=3923 题意描述: 输入一个n*m的屏幕 该屏幕内有至少一个对话框(每个对话框都有对应的字母表示) 判断并输出该屏幕内处于最表层的对话 ...
- POJ 1008 简单模拟题
e.... 虽然这是一道灰常简单的模拟题.但是米做的时候没有读懂第二个日历的计时方法.然后捏.敲完之后华丽的WA了进一个点.坑点就在一年的最后一天你是该输出本年的.e ...但是我好想并没有..看di ...
- UVa232.Crossword Answers
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
随机推荐
- HDU-3549 最大流模板题
1.HDU-3549 Flow Problem 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 3.总结:模板题,参考了 http://ww ...
- C++的STL中vector内存分配方法的简单探索
STL中vector什么时候会自动分配内存,又是怎么分配的呢? 环境:Linux CentOS 5.2 1.代码 #include <vector> #include <stdio ...
- ListView的HeaderView和Footer
HeaderView介绍 HeaderView用法 属性中添加 ListView中属性listHeader和overScrollHeader区别: android:overScrollHeader=& ...
- curl测试网页响应时间
连接时间: curl -s -o /dev/null -w "%{time_connect}\n" http://www.joinpay.com 传输时间: curl -s -o ...
- nginx连接php fastcgi配置
匹配到php结尾的文件抛到后端 后端php端口9000
- Spark RDD Operations(2)
处理数据类型为Value型的Transformation算子可以根据RDD变换算子的输入分区与输出分区关系分为以下几种类型. 1)输入分区与输出分区一对一型. 2)输入分区与输出分区多对一型. 3)输 ...
- js添加确认删除操作注意事项
function delsure(){ if(confirm('确认删除吗?')){ return true;//点击确定则返回这里的内容 }else{ return false; } } 在表单中添 ...
- javaweb实验五
product类: package com.lab;public class Product { private int id; // 商品编号 private S ...
- php 的包管理工具 composer
官方网站 https://getcomposer.org/ 下载地址 https://getcomposer.org/download/ 安装教程 https://laravist.com/serie ...
- 使用 mock.js 让前端开发与后端独立
直接上代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...