/*
1.因为输入的两个整数决定了这一次循环要接收的字符数,
所以可以通过判断第一个数字是否为0来结束输入。
2. 判断是否标记数字。whitesquare的左边或上边若没有whitesquare,则可以标上
3.打印时如何判断一个标号是已经打印还是应该要从他打印起?
设置记号法不可取,因为across输出会影响down输入。
Across: 对于某一行,从第一个开始输出,直到遇到边界或者遇到黑格
Down:
如果这个whitesquare的上面不是whitesquare即可要以它为起始
*/
#include<stdio.h>
char words[10][10];
int def[10][10] = {0};
int main(){
int r,c;
int index=1;
// int defcount=1;
int firstcase=1;
while(scanf("%d",&r) && r!= 0){
scanf("%d",&c);
getchar(); //不可忽略
for(int i=0; i<r; i++){
for(int j=0; j<c; j++)
words[i][j] = getchar();
getchar();
}
//处理
int defcount = 1;
for(int i=0; i<c; i++){
if(words[0][i] != '*' )
def[0][i] = defcount++;
}
for(int i=1; i<r; i++){
for(int j=0; j<c; j++){
if(j==0){
if(words[i][j] != '*')
def[i][j] = defcount++;
}
else{
if( (words[i-1][j] == '*' || words[i][j-1] == '*')&&(words[i][j] != '*') )//也要求words[i][j]不能为'*'
def[i][j] =defcount++;
}
}
}
if(!firstcase)
printf("\n");
printf("puzzle #%d:\n",index++);
printf("Across\n");
//横向输出
for(int i=0; i<r; i++){
for(int j=0; j<c; ){
if(words[i][j] != '*'){
printf("%3d.",def[i][j]);
while(words[i][j] != '*'){
printf("%c",words[i][j]);
j++;
if(j == c)
break;
}
printf("\n");
}
else j++;
}
}
printf("Down\n");
for(int i=0; i<r; i++){
int idex=i;
for(int j=0; j<c; j++ ){
if ( (words[i][j] != '*' && i==0 )|| (i!= 0 && words[i-1][j] == '*' && words[i][j] != '*') )
{
printf("%3d.",def[i][j]);
while(words[i][j] != '*' && i<r){
printf("%c",words[i][j]);
i++;
}
printf("\n");
}
i = idex;
}
}
firstcase = 0;
}
return 0;
}
Uva232 Crossword Answers
最新推荐文章于 2023-11-26 16:08:19 发布