UVA.232 Crossword Answers
Crossword Answers
小总结
1.括号能少写少写。
2.多使用复合语句中的++,- -,不影响可读性,代码简洁高效。
3.循环时尽量使用前置的++或- - ,效率高。
4.注意题目中的大小写。
题意分析
给出一组字符串,按照题目要求编号。第一行和第一列所有非黑色的方格均要编号,对于其他的白色空格,如果此空格上方或者左方有黑色方格,那么也要编号。编号按照自左到右,自上到下的顺序编号。
然后就是按照题目要求分别输出横向,纵向的编号和对应的单词,注意一定要按照编号的大小顺序输出。
测试数据补充
9 9
ANTIC*ACE
DOUCE*MUG
ARTILLERY
**ELL*NIP
HOLY*RIOT
ARA*VAT**
SIGNIFIED
TOE*STERE
ENS*ASSAY
9 9
*LAUREL**
PASSERINE
EST*CABER
WHOA*SETA
**UTTER**
LINT*RARE
INDIE*TON
INERTNESS
**DECODE*
9 9
OREO*EBON
LAMP*RODE
EGOTISTIC
OATS*TANK
**I***N**
UPON*LIVE
SYNODICAL
ERAS*MASS
DELE*ALEE
1 1
*
1 1
Z
6 5
*****
*HAIR
RI*L*
E*ILD
****Z
*****
0
对应的答案为
puzzle #1:
Across
1.ANTIC
6.ACE
9.DOUCE
10.MUG
11.ARTILLERY
13.ELL
14.NIP
15.HOLY
17.RIOT
18.ARA
19.VAT
20.SIGNIFIED
24.TOE
25.STERE
26.ENS
27.ASSAY
Down
1.ADA
2.NOR
3.TUTELAGES
4.ICILY
5.CELL
6.AMENITIES
7.CURIO
8.EGYPT
12.L
15.HASTE
16.ORION
17.RAFTS
19.VISA
21.N
22.ERA
23.DEY
puzzle #2:
Across
1.LAUREL
7.PASSERINE
10.EST
11.CABER
12.WHOA
14.SETA
15.UTTER
17.LINT
19.RARE
22.INDIE
24.TON
25.INERTNESS
27.DECODE
Down
1.LASH
2.ASTOUNDED
3.US
4.REC
5.ERASER
6.LIBERATED
7.PEW
8.NET
9.ERA
13.ATTIRE
16.T
17.LII
18.INN
20.ROSE
21.ENS
23.ETC
26.NO
puzzle #3:
Across
1.OREO
5.EBON
9.LAMP
10.RODE
11.EGOTISTIC
13.OATS
14.TANK
15.I
16.N
17.UPON
20.LIVE
23.SYNODICAL
25.ERAS
26.MASS
27.DELE
28.ALEE
Down
1.OLEO
2.RAGA
3.EMOTIONAL
4.OPTS
5.ERST
6.BOTANICAL
7.ODIN
8.NECK
12.I
17.USED
18.PYRE
19.NOSE
20.LIMA
21.VASE
22.ELSE
24.D
puzzle #4:
Across
Down
puzzle #5:
Across
1.Z
Down
1.Z
puzzle #6:
Across
1.HAIR
5.RI
6.L
7.E
8.ILD
10.Z
Down
1.HI
2.A
3.ILL
4.R
5.RE
8.I
9.DZ
代码总览
/*
Title:UVA.232
Author:pengwill
Date:2016-12-16
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char map[11][11];
int id[11][11];
typedef struct wd{
char name[10];
int pos;
}node;
node data[100];
void input(int r,int l)
{
int i,j;
for(i = 0;i<r;i++)
gets(map[i]);
}
void lable(int r,int l)
{
int i,j,flag = 0,cnt =1;
for(i = 0;i<r;i++){
flag = 0;
for(j = 0;j<l;j++)
if((map[i][j]!='*'&&!flag)||(!i&&map[i][j]!='*')||(map[i][j-1] =='*'&&map[i][j]!='*')||(map[i-1][j] =='*'&&map[i][j]!='*')){
id[i][j] = cnt; flag =1; cnt++;
}else if(map[i][j]!='*'&&flag){
id[i][j] = 0;
}else if(map[i][j] =='*'){
flag = 0; id[i][j] = -1;
}
}
}
void dor(int r,int l)
{
int i, j;
printf("Across\n");
for(i = 0;i<r;i++)
for(j = 0;j<l;j++){
if(id[i][j] != -1)
if(id[i][j]){
printf("%3d.",id[i][j]);
while(j<l&&id[i][j]!=-1){printf("%c",map[i][j++]);}
printf("\n");
}
}
}
bool cmp(node a, node b)
{
return a.pos<b.pos;
}
void dol(int r, int l)
{
int i,j,cnt = 0;
printf("Down\n");
for(j = 0;j<l;++j)
for(i = 0;i<r;++i){
if(id[i][j] != -1){
if(id[i][j]){
int save = 0;
data[cnt].pos = id[i][j];
while(i<r&&id[i][j]!=-1){data[cnt].name[save++] = map[i++][j];}
data[cnt].name[save] ='\0';
cnt++;
}
}
}
sort(data,data+cnt,cmp);
for(i = 0;i<cnt;i++)
printf("%3d.%s\n",data[i].pos,data[i].name);
}
int main()
{
int r,l,cnt = 0;
while(scanf("%d",&r)&& r){
if(cnt) printf("\n");
cnt++;
scanf("%d",&l); getchar();
input(r,l);
lable(r,l);
printf("puzzle #%d:\n",cnt);
dor(r,l);
dol(r,l);
}
return 0;
}