纵横字谜的答案 (UVa232)

article/2025/10/6 9:13:47

纵横字谜的答案
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit  Status

Description

Download as PDF


 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 ( tex2html_wrap_inline39 and tex2html_wrap_inline41 ), 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 ccharacters 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:
Across1.AT3.O
Down1.A2.TOpuzzle #2:
Across1.AIM4.DEN7.ME8.ONE9.UPON11.TO12.SO13.ERIN15.SA17.OR18.IES19.DEA
Down1.A2.IMPOSE3.MEO4.DO5.ENTIRE6.NEON9.US10.NE14.ROD16.AS18.I20.A

题意:输入一个r行c列的网格,黑格用*号表示,每个白格都填有一个字母。如果一个白格的左边相邻位置或者上边相邻位置没有白格(可能是黑格,也可能出了网格边界),则称这个白格是一个起始格。首先把所有起始格从左到右,从上到下顺序编号1,2,3,。。。。要求找出所有横向单词。这些单词必须从一个起始格开始,向右延伸到一个黑格的左边或者整个网格的最右边。最后找出所有的竖向单词。


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 105
#define MAXN 2005
#define mod 1000000009
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
typedef long long ll;
using namespace std;struct St
{int x,y;int r,c;
}st[111];char mp[12][12];
int n,m;int main()
{int cas=0;while (scanf("%d",&n),n){scanf("%d",&m);
//        if (cas) printf("\n");for (int i=0;i<n;i++)scanf("%s",mp[i]);
//        for (int i=0;i<n;i++)
//            printf("%s\n",mp[i]);int num=1;for (int i=0;i<n;i++){for (int j=0;j<m;j++){if(mp[i][j]!='*'){if ((i-1)<0||(j-1)<0||mp[i-1][j]=='*'||mp[i][j-1]=='*'){st[num].x=i;st[num].y=j;if ((j-1)<0||mp[i][j-1]=='*')  st[num].r=1;  else  st[num].r=0;if ((i-1)<0||mp[i-1][j]=='*')  st[num].c=1;  else  st[num].c=0;num++;}}}}if (cas)printf("\n");
//        printf("num=%d\n",num);printf("puzzle #%d:\nAcross\n",++cas);for (int i=1;i<num;i++){if (st[i].r){printf("%3d.",i);for (int j=st[i].y;j<m;j++){if (mp[ st[i].x ][j]=='*')break;printf("%c",mp[ st[i].x ][j]);}printf("\n");}}
//        printf("num=%d\n",num);printf("Down\n");for (int i=0;i<num;i++){if (st[i].c){printf("%3d.",i);for (int j=st[i].x;j<n;j++){if (mp[j][ st[i].y ]=='*')break;printf("%c",mp[j][ st[i].y ]);}printf("\n");}}
//        printf("\n");}return 0;
}




http://chatgpt.dhexx.cn/article/HJdUalV5.shtml

相关文章

Scratch 教程《元宵猜灯谜》

程序演示 元宵节到了&#xff0c;用Scratch给小朋友做一个猜灯谜游戏&#xff01; 课程引入 青玉案元夕 【宋】辛弃疾 东风夜放花千树&#xff0c;更吹落、星如雨。宝马雕车香满路。凤箫声动&#xff0c;玉壶光转&#xff0c;一夜鱼龙舞。 蛾儿雪柳黄金缕&#xff0c;笑语盈盈暗…

Python 猜字谜游戏

import random WORDS ("python","import","hello","difficult","easy") print("欢迎来到猜单词游戏&#xff0c;请将乱序后的单词组成正确的单词") iscontinue "y" while iscontinue"y" or…

c语言猜字谜(详解)(后附完整源码)

c语言猜字谜 一.游戏前置二.游戏实现1.让电脑生成随机数2.让玩家重复输入3.输赢判断 一.游戏前置 向其他游戏一样&#xff0c;在游戏开始前&#xff0c;我们需要一个菜单让玩家进行选择 所以我们需要以下功能 1.一个能让玩家进行选择的函数&#xff08;switch&#xff09; 2.玩…

猜字谜小游戏

猜字谜小游戏 思路 : 先写一个菜单函数,打印一个菜单,获取用户输入 从菜单函数中调用Game函数 写Game函数里面的内容 从主函数中调用菜单函数 #include<stdio.h> #include<stdlib.h>//里面包含rand函数,system函数 #include<time.h> void Game(void);//声明…

猜字谜游戏

一个非常简单的猜数字游戏&#xff0c;在一个限定的范围内&#xff0c;系统会给出一个随机的未知数&#xff0c;让玩家自己去猜&#xff0c;并且还会根据玩家输入的数给出相应的提示。如下图&#xff1a; 原理很简单&#xff0c;主要通过Random函数构建循环方法&#xff0c;再用…

【Flink】FLink Assigned key must not be null

1.场景1 1.1 概述 flink报错: Caused by: java.lang.NullPointerException: Assigned key must not be null! 具体如下 原因 keyBy的字段不能为null M.参考 Flink运行出现Assigned key must not be null

vuex报错Computed property “xxx“ was assigned to but it has no setter.

当使用vuex存储数据时&#xff0c;常常有这样的需求&#xff1a;输入框显示并动态修改state中的数据。 我们第一个反应就是使用v-model直接绑定state中的数据&#xff0c;虽然确实可以显示和修改&#xff0c;但是控制台会报错&#xff0c;所以不能采取这种方式。 案例如下&…

可编程渲染管线报错 Unity Universal RP asset not assigned

可编程渲染管线报错 Unity Universal RP asset not assigned 解决 1.创建urp资产 创建成功如下图 2.打开Edit > Project Settings… > Graphics 3.设置资产 如果你安装了URP包&#xff0c;当你编写自定义渲染管线时&#xff0c;既是你设置的上图资产也会报同样的错误。…

【Flink】FLink assigned slot xx was removed

1.概述 flink报错 org.apache.flink.util.FlinkException: The assigned slot container_e08_1539148828017_15937_01_003564_0 was removed. at org.apache.flink.runtime

Flink线上问题: The assigned slot container_xxx was removed

Flink线上问题: The assigned slot container_xxx was removed 客户现场使用Flink(on Yarn)进行数据抽取,Source是JDBC,Sink是Kafka,客户反映流程差不多跑10天左右就挂,让我看看. 环境: Flink: 1.5.2 jdk: 1.8.0_25 Hadoop: 2.4.1 jobmanger和TaskManger都分配1G内存 首先…

There‘s no Qt version assigned to project xxx.vcxproj for configuration Debug/x64

Qt系列文章目录 文章目录 Qt系列文章目录前言一、 分析错误原因二、解决步骤1.选择Qt版本2.检查环境变量3.重新构建工程 There’s no Qt version assigned to project xxx.vcxproj for configuration Debug/x64 前言 如果你想了解关于Qt与VS2019开发环境搭建&#xff0c;可以至…

SAP ABAP一组关键字 IS BOUND, IS NOT INITIAL和IS ASSIGNED的用法辨析

ABAP里的IS BOUND, IS NOT INITIAL和IS ASSIGNED这组关键字&#xff0c;如果平时不留心&#xff0c;很容易理解地似是而非。今天我们就来说一说它们的区别。 先把SAP帮助文档抄过来&#xff1a; IS BOUND It checks whether a reference variable contains a valid referenc…

【FLink】Assigned key must not be null

1.概述 我的flink任务报错Assigned key must not be null,但是我把keyby用到的字段已经提前做了非空过滤,还是偶尔会报这个错。 还没法复现这个问题。 对应的源码位于 public static int assignToKeyGroup(Object key, int maxParallelism) {Preconditions.checkNotNull(k…

xxx is assigned a value but never used 报错

xxx is assigned a value but never used报错 找到路径 package.json文件 -> devDependencies -> rules 添加以下代码 "rules": {"generator-star-spacing": "off","no-debugger": "off","no-tabs": &quo…

There is no Qt version assigned to project

问题描述&#xff1a;最近从用vs2017Qt5.13编写程序&#xff0c;从一台已经编译好的电脑上拷贝到另外一台有vs2017和Qt5.13环境的电脑&#xff0c;但是问题来了&#xff0c;出现了如下图片的描述&#xff1a; 解决方法&#xff1a;首先检查Qt Project Setting&#xff0c;如果界…

Unity Universal RP asset not assigned

Unity Universal RP asset not assigned 问题解决 问题 项目导入URP后&#xff0c;相机出现这个错误 解决 打开Edit > Project Settings… > Graphics在可脚本渲染管道设置字段中&#xff0c;添加前面创建的通用渲染管道资产。 参考: Unity Doc

IDEA报错private field “xxx“ is never assigned解决

文章目录 1.现象2.解决办法 1.现象 在IDEA中&#xff0c;开发Spring项目时&#xff0c;在一个类中使用Autowired注解注入成员变量时&#xff0c;IDEA会在该成员变量上报类似于如下警告&#xff1a; 一开始还以为是代码哪里配置的有问题&#xff0c;以前也没遇到过啊。 暂时怀…

Computed property was assigned to but it has no setter问题随记

初始代码&#xff1a;弹窗使用dialogtablvisible 但是其他位置改变了这个值 在methods中修改了这个属性的值 当该事件发生时会报这个错误Computed property was assigned to but it has no setter 解决方法其实很简单&#xff0c;组件中定义的computed属性缺少setter,使用过co…

前端开发:Vue报错Computed property “show“ was assigned to but it has no setter的解决方法

前言 在前端开发中,使用Vue的时候关于组件使用是非常常见的操作,而且也会遇到各式各样的问题,尤其是刚接触前端开发的开发者。本篇博文分享一下在封装关于Vue的组件的时候,通过计算属性监听父子组件传值提示警告的问题,即:Computed property "show" was assign…