Uva 232 一个换行WA 了四次
由于UVA OJ上没有Wrong anwser,搞的多花了好长时间去测试程序,之前一直以为改OJ有WA,后来网上一搜才知道没有WA,哎哎浪费了好长时间。此博客用来记录自己的粗心大意。
链接地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=168
232 - Crossword AnswersTime limit: 3.000 seconds |
|
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 |
源代码如下:
#include<iostream>
#include<string.h>
using namespace std;
#define SIZE 20
#define MAX 200
int main()
{ int pu[SIZE][SIZE];
char s[SIZE][SIZE];
char str[MAX][SIZE];
int r, c;
int T=0; while(cin>>r && r!= 0 )
{
int count=1;
for(int i=0; i<MAX; i++)
{
for(int j=0; j<SIZE ; j++)
str[i][j]='\0';
}
cin>>c;
for(int i=0; i<r ; i++)
{
for(int j=0; j<c ; j++)
{ pu[i][j]=0;
cin>>s[i][j]; if( i==0 ) //diyihang
{
if(s[i][j] != '*')
{
pu[i][j]=count;
count++;
}
// else s[i][j]=0; }
else
{
if( j==0 && s[i][j] != '*')
{ pu[i][j]=count;
count++;
}
else if(s[i][j-1]=='*' && s[i][j] != '*')
{
pu[i][j]= count;
count++;
}
else if(s[i-1][j]=='*' && s[i][j] != '*')
{
pu[i][j]= count;
count++;
}
else ;
} }
} if(T >0 ) cout<<endl; //我之前在后面直接cout<<endl,这样便会造成会多输出一空行,造成WA,所以一定要切记!
T++;
cout<<"puzzle #"<<T<<":"<<endl;
cout<<"Across"<<endl;
for(int i=0; i<r ; i++)
{ bool flag = false;
int start=1;
// bool sflag= false;
for(int j=0; j<c ; j++)
{
if( s[i][j] == '*')
{ if(flag)
{
cout<<endl;
flag = false;
}
}
else
{ if( !flag )
{
start =pu[i][j];
if(start <10 )
cout<<" ";
else cout<<" ";
cout<<start<<".";
flag = true;
}
cout<<s[i][j];
// flag = true;
if( j== c-1)
{
cout<<endl;
flag = false;
}
} } }
// cout<<"Down"<<endl;
int locstr=0;
// int start=1;
for(int j=0; j<c ; j++)
{ bool flag = false; int countstr=0;
for(int i=0; i<r ; i++)
{ if( s[i][j] =='*' )
{
if(flag)
{
// cout<<endl;
// flag = false;
str[locstr][countstr]='\0';
// locstr++;
countstr=0;
flag = false;
} }
else
{
if( !flag )
{ locstr =pu[i][j]; flag = true;
// str[locstr][countstr++]=""
/* start =pu[i][j];
if(start <10 )
cout<<" ";
else cout<<" ";
cout<<start<<".";
flag = true;
*/
}
// cout<<s[i][j];
str[ locstr][countstr++]=s[i][j];
// flag = true;
if( i== r-1)
{
// cout<<endl;
// flag = false;
str[locstr][countstr]='\0';
// locstr++;
countstr=0;
flag = false;
} } } }
// qsort(str,MAX,sizeof(str[0]),comp);
cout<<"Down"<<endl;
for(int i=0; i<MAX; i++)
{
int len = strlen(str[i]);
if(len >0 )
{ if(i <10 )
cout<<" ";
else cout<<" ";
cout<<i<<".";
cout<<str[i]<<endl;
// cout<<start<<"."; } } // cout<<endl;
} return 0;
}
Uva 232 一个换行WA 了四次的更多相关文章
- Qt applendPlainText()/append() 多添加一个换行解决方法
Qt applendPlainText()/append() 多添加一个换行解决方法 void ConsoleDialog::appendMessageToEditor(const QString & ...
- print默认在末尾添加一个换行符,但其实也可以不用!
白月黑羽今天给大家分享另外一个冷知识:) python中 print函数打印信息时默认添加一个换行符,所以你看到一条print语句,则单独占一行,那是否可以不要换行符呢? 答案是肯定的,当然可以,可用 ...
- express + mongodb 搭建一个简易网站 (四)
express + mongodb 搭建一个简易网站 (四) 目前网站整体页面都已经能全部展示了,但是,整个网站还有两个块需要做完才能算完整,一个连接数据库,目前网站上的数据都是抓取的本地假数据,所以 ...
- JavaScript确定一个字符串是否包含在另一个字符串中的四种方法
一.indexOf() 1.定义 indexOf()方法返回String对象第一次出现指定字符串的索引,若未找到指定值,返回-1.(数组同一个概念) 2.语法 str.indexOf(searchVa ...
- 利用django创建一个投票网站(四)
创建你的第一个 Django 项目, 第四部分 这一篇从第三部分(zh)结尾的地方继续讲起.我们将继续编写投票应用,专注于简单的表单处理并且精简我们的代码. 编写一个简单的表单 让我们更新一下在上一个 ...
- 用C写一个web服务器(四) CGI协议
* { margin: 0; padding: 0 } body { font: 13.34px helvetica, arial, freesans, clean, sans-serif; colo ...
- UVA 232 Corssword Answer
题意:输入m*n大小的字符串(里面有*,*为黑格,其他为白格),然后对它编号,编号规则为从左到右,从上往下,且左边或上面没有白格(可能是黑格或越界),如下图: 注意: ①除第一次输出答案外,其余每次输 ...
- Play Framework 完整实现一个APP(十四)
添加测试 ApplicationTest.java @Test public void testAdminSecurity() { Response response = GET("/adm ...
- 调度系统任务创建---创建一个MultiJob的任务(四)
我们如果下面这种拓扑结构的调度任务,该任务的拓扑结构就是一个有向五环图DAG,有fork,有join的操作等. 可以通过jenkins创建MultiJob的任务实现: 实例任务的拓扑结构: Multi ...
随机推荐
- .NET中使用WebService,以及和一般处理程序、类库的区别
首先我们来看一下如何创建Web Service 首先在解决方案中新建项,选择ASP.NETWeb应用程序 然后选择一个空的项目就可以,单击确定 项目建完之后,在项目上右键-->添加-->新 ...
- 无重复字符的最长子串[双指针+哈希表] LeetCode.3
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc&qu ...
- 搭建本地的idea激活服务器
前言 博主用的是idea这个IDE,因为最近idea官方打击第三方激活服务有些严重,所以我的idea经常处于今天可以用,到了明天就不能用的状态,所以,从idea激活的网站找到了本地的id ...
- 实验Oracle数据文件被误删除的场景恢复
环境:RHEL 5.4 + Oracle 11.2.0.3 背景:数据库没有备份,数据库文件被误操作rm,此时数据库尚未关闭,也就是对应句柄存在,如何快速恢复? 1.某个普通数据文件被删除 2.所有数 ...
- js获取Cookie,获取url参数
function getCookie(name) { var strCookie = document.cookie; var arrCookie = strCookie.split("; ...
- POJ 1015 陪审团问题
题意略. 思路: 这个题目开始我本来打算用个二维dp,令dp[ i ][ j ]为考虑前i个人,有j个名额的时候,我所能获取的最小差,后来发现不好转移.因为dp[ i ][ j ]有可能是+2, 也有 ...
- [Python] 通过采集两万条数据,对《无名之辈》影评分析
一.说明 本文主要讲述采集猫眼电影用户评论进行分析,相关爬虫采集程序可以爬取多个电影评论. 运行环境:Win10/Python3.5. 分析工具:jieba.wordcloud.pyecharts.m ...
- JVM参数配置&&命令工具
JVM参数配置 大致方向:JVM调优的目的是保证在一定吞吐量的情况下尽可能的减少GC次数,从而减少系统停顿时间,提高服务质量和效率. 其中减少GC次数的原则: 将新生代转换成老年代的数量降至最少(及时 ...
- 怎样用QT在windows环境通过编程卸载installShield打包的程序
通常情况下,如果是一个完备的软件,我们可以通过启动软件的uninstaller.exe之类的程序来完成卸载.但是使用installShield打包的程序,本身可能并不含有这类卸载程序.此时,我们可以通 ...
- ElasticSearch专栏
1.es的分布式架构原理(es是如何实现分布式)? elasticsearch设计的理念就是分布式搜索引擎,底层其实还是基于lucene的.核心思想就是在多台机器上启动多个es进程实例,组成了一个es ...