Uva232 Crossword Answers

/*
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;
	
	
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值