UVa232.Crossword Answers
题目链接: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的更多相关文章
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- UVa 232 Crossword Answers
Crossword Answers A crossword puzzle consists of a rectangular grid of black and white squares and ...
- 紫书第三章训练1 D - Crossword Answers
A crossword puzzle consists of a rectangular grid of black and white squares and two lists of defini ...
- Crossword Answers -------行与列按序输出
题目链接:https://vjudge.net/problem/UVA-232#author=0 题意:关键句:The de nitions correspond to the rectangular ...
- Crossword Answers UVA - 232
题目大意 感觉挺水的一道题.找出左面右面不存在或者是黑色的格子的白各,然后编号输出一横向单词和竖向单词(具体看原题) 解析 ①找出各个格子的编号 ②对每个节点搜索一下 ③输出的时候注意最后一个数据后面 ...
- 【习题 3-6 UVA - 232】Crossword Answers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟题.注意场宽为3 [代码] #include <bits/stdc++.h> using namespace std ...
- [刷题]算法竞赛入门经典 3-4/UVa455 3-5/UVa227 3-6/UVa232
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa455:Periodic Strings 代码: //UVa455 #inclu ...
- Uva 232 一个换行WA 了四次
由于UVA OJ上没有Wrong anwser,搞的多花了好长时间去测试程序,之前一直以为改OJ有WA,后来网上一搜才知道没有WA,哎哎浪费了好长时间.此博客用来记录自己的粗心大意. 链接地址:htt ...
- HDU3038 How Many Answers Are Wrong[带权并查集]
How Many Answers Are Wrong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
随机推荐
- c语言指针点滴1
#include <stdio.h> #include <stdlib.h> void main() { int *p = NULL;//指针开始最好都初始化为空 if(p = ...
- pyqt cvs保存
# -*- coding: utf-8 -*-__author__ = 'Administrator'import sys, csvfrom PyQt4 import QtGui, QtCore cl ...
- 使用python监听、模拟鼠标键盘事件
最近守望职业选手疑似开挂事件挺热闹的,在下小菜一枚,并不能从视频中看出端倪.看了一些关于外挂的讨论,自动点射和压枪只需在鼠标驱动上做些改动即可,自瞄或其他高级功能则需要读内存或修改游戏文件,检测也更容 ...
- 浏览器内核Trident/Gecko/WebKit/Presto
“浏览器内核”主要指渲染引擎(Rendering Engine),负责解析网页语法(如HTML.JavaScript)并渲染.展示网页.因此,所谓的浏览器内核通常也就是指浏览器所采用的渲染引擎, 渲染 ...
- C#Equal的使用
代码如下: public partial class FramMain : Form { public FramMain() { InitializeComponent(); } private vo ...
- Python进阶之路---1.3python环境搭建
python环境安装 windows python环境安装 下载安装包 https://www.python.org/downloads/ 安装并指定安装目录 C:\python2 ...
- Javascript进阶篇——(DOM—节点---插入、删除和替换元素、创建元素、创建文本节点)—笔记整理
插入节点appendChild()在指定节点的最后一个子节点列表之后添加一个新的子节点.语法: appendChild(newnode) //参数: //newnode:指定追加的节点. 为ul添加一 ...
- F# 越用越喜欢
F# 越用越喜欢 最近由于需要,把遗忘了几年的F#又捡了起来.说捡了起来,倒不如说是从头学习,原来学的早已经忘了!所谓学过,只不过看过一本<F# 语言程序设计> (郑宇军 凌海风 编著 - ...
- Windows服务承载WCF
Source文件 ------------------------- using System; using System.Collections.Generic; using System.Linq ...
- Contains Duplicate,Contains Duplicate II,Contains Duplicate III
217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your ...