My idea is that all around the grid is set to ' * ', setting the sign array record starting grid
#include <stdio.h>#include<cstring>Chara[ -][ -];intsign[ -][ -];intn =1;intMain () {intR, C, CNT, yes, first =1; while(SCANF ("%d", &r) = =1) {memset (sign,0,sizeof(sign)); CNT=1; Yes=0; if(r = =0) Break; scanf ("%d",&B); GetChar (); for(inti =1; I <= R; i + +) { for(intj =1; J <= C; J + +) {scanf ("%c",&a[i][j]);} GetChar (); } for(inti =0; I <= r+1; i + +) a[i][0] = a[i][c+1] ='*'; for(intj =0; J <= c+1; J + +) a[0][J] = a[r+1][J] ='*'; for(inti =1; I <= R; i++) for(intj =1; J <= C; J + +) if((a[i-1][J] = ='*'|| a[i][j-1] =='*') &&a[i][j]! ='*') Sign[i][j]= cnt + +; if(!First ) printf ("\ n"); First=0; printf ("Puzzle #%d:\nacross\n", N); for(inti =1; I <= R; i + +) for(intj =1; J <= C; J + +) { if(Sign[i][j]) printf ("%3d.", Sign[i][j]); while(A[i][j]! ='*') {printf ("%c", A[i][j]); J++; Yes=1; } if(yes) {printf ("\ n"); Yes=0; }} printf ("down\n"); for(inti =1; I <= R; i + +) for(intj =1; J <= C; J + +) { intm =i; if(Sign[i][j]) printf ("%3d.", Sign[i][j]); while(A[i][j]! ='*') {printf ("%c", A[i][j]); A[I][J]='*'; SIGN[I][J]=0; Yes=1; I++; } if(yes) {printf ("\ n"); Yes=0; } I=m; } N++; } return 0;}
Uva 232-crossword Answers