题目大意

感觉挺水的一道题。找出左面右面不存在或者是黑色的格子的白各,然后编号输出一横向单词和竖向单词(具体看原题)

解析

①找出各个格子的编号

②对每个节点搜索一下

③输出的时候注意最后一个数据后面没有空行,也就是空行得在上面出

代码

#include <bits/stdc++.h>
using namespace std;
char mp[100][100];
int bk[100][100],bk1[100][100],bk2[100][100];
int n,m;
void dfs(int x,int y)
{
printf("%3d.",bk[x][y]);
while(1)
{
if(mp[x][y]!='*'&&y<m)
{
cout<<mp[x][y];
y++;
bk1[x][y]=1;
}
else
{
cout<<endl;
break;
}
}
}
void dfs1(int x,int y)
{
printf("%3d.",bk[x][y]);
while(1)
{
if(mp[x][y]!='*'&&x<n)
{
cout<<mp[x][y];
x++;
bk2[x][y]=1;
}
else
{
cout<<endl;
break;
}
}
}
int main()
{
/*ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);*/
int t=1;
while(cin>>n>>m)
{
if(n==0)
break;
int p=0;
memset(bk,0,sizeof(bk));
memset(bk1,0,sizeof(bk1));
memset(bk2,0,sizeof(bk2));
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>mp[i][j];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(i-1<0||j-1<0||mp[i-1][j]=='*'||mp[i][j-1]=='*')
if(mp[i][j]!='*')
bk[i][j]=++p;
if(t>1)
cout<<"\n";
printf("puzzle #%d:\n",t++);
printf("Across\n");
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(!bk1[i][j]&&mp[i][j]!='*')
dfs(i,j);
printf("Down\n");
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(!bk2[i][j]&&mp[i][j]!='*')
dfs1(i,j);
//cout<<"\n";
}
}

Crossword Answers UVA - 232的更多相关文章

  1. UVa 232 Crossword Answers

     Crossword Answers  A crossword puzzle consists of a rectangular grid of black and white squares and ...

  2. UVa232.Crossword Answers

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. Uva 232 一个换行WA 了四次

    由于UVA OJ上没有Wrong anwser,搞的多花了好长时间去测试程序,之前一直以为改OJ有WA,后来网上一搜才知道没有WA,哎哎浪费了好长时间.此博客用来记录自己的粗心大意. 链接地址:htt ...

  4. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  5. 【习题 3-6 UVA - 232】Crossword Answers

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟题.注意场宽为3 [代码] #include <bits/stdc++.h> using namespace std ...

  6. 紫书第三章训练1 D - Crossword Answers

    A crossword puzzle consists of a rectangular grid of black and white squares and two lists of defini ...

  7. UVA 232 Corssword Answer

    题意:输入m*n大小的字符串(里面有*,*为黑格,其他为白格),然后对它编号,编号规则为从左到右,从上往下,且左边或上面没有白格(可能是黑格或越界),如下图: 注意: ①除第一次输出答案外,其余每次输 ...

  8. Crossword Answers -------行与列按序输出

    题目链接:https://vjudge.net/problem/UVA-232#author=0 题意:关键句:The de nitions correspond to the rectangular ...

  9. [刷题]算法竞赛入门经典 3-4/UVa455 3-5/UVa227 3-6/UVa232

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 题目:算法竞赛入门经典 3-4/UVa455:Periodic Strings 代码: //UVa455 #inclu ...

随机推荐

  1. hibernate 下载

    https://sourceforge.net/projects/hibernate/files/hibernate-orm/5.0.7.Final/ http://sourceforge.net/p ...

  2. beego2---入门

    package main //beego既可以建立web应用也可以建立api应用 //beego是一个gohttp服务器的高层封装, import ( _ "beego1/routers&q ...

  3. HttpClient-01基本概念

    Http 协议应该是互联网中最重要的协议.持续增长的 web 服务.可联网的家用电器等都在继承并拓 展着 Http 协议,向着浏览器之外的方向发展. 虽然 jdk 中的 java.net 包中提供了一 ...

  4. 从csv文件读取数据到二维vector

    void ReadDataFromCsv(std::string &filename, std::vector<std::vector<std::string> > & ...

  5. Spark 多项式逻辑回归__二分类

    package Spark_MLlib import org.apache.spark.ml.Pipeline import org.apache.spark.ml.classification.{L ...

  6. Java多线程系列二——Thread类的方法

    Thread实现Runnable接口并实现了大量实用的方法 public static native void yield(); 此方法释放CPU,但并不释放已获得的锁,其它就绪的线程将可能得到执行机 ...

  7. Unity项目 - Boids集群模拟算法

    1987年Craig W.Reynolds发表一篇名为<鸟群.牧群.鱼群:分布式行为模式>的论文,描述了一种非常简单的.以面向对象思维模拟群体类行为的方法,称之为 Boids ,Boids ...

  8. Akka源码分析-Cluster-Singleton

    akka Cluster基本实现原理已经分析过,其实它就是在remote基础上添加了gossip协议,同步各个节点信息,使集群内各节点能够识别.在Cluster中可能会有一个特殊的节点,叫做单例节点. ...

  9. [转]C++常用字符串分割方法实例汇总

    本文实例汇总了C++常用字符串分割方法,分享给大家供大家参考.具体分析如下: 我们在编程的时候经常会碰到字符串分割的问题,这里总结下,也方便我们以后查询使用. 一.用strtok函数进行字符串分割 原 ...

  10. C# 自动批量导入图片到数据库中

    using Model; using System; using System.Collections.Generic; using System.Data; using System.Data.Sq ...