Horizontal vertical search for words
Mark First, then record the answer
The final sort must be aligned with the first and last position.
1#include <iostream>2#include <cstring>3#include <algorithm>4#include <iomanip>5 using namespacestd;6 structt{7 intnum;8 Charans[ the];9}down[ -],acr[ -];Ten intr,c,cnt1,cnt2,cnt,tmp,k; One Chars[ the][ the]; A intfl[ the][ the]; - BOOLFlag; - BOOLCMP (T a,t B) the { - returna.num<B.num; - } - voidmark () + { -Memset (fl,0,sizeof(fl)); + for(intI=0; i<r;i++)if(s[i][0]!='*') fl[i][0]=1; A for(intI=0; i<r;i++) at for(intj=1; j<c;j++) - if(s[i][j-1]=='*'&&s[i][j]!='*') fl[i][j]=1; - for(intI=0; i<c;i++)if(s[0][i]!='*') fl[0][i]=1; - for(intI=1; i<r;i++) - for(intj=0; j<c;j++) - if(s[i-1][j]=='*'&&s[i][j]!='*') fl[i][j]=1; inCnt=1; - for(intI=0; i<r;i++) to for(intj=0; j<c;j++) + if(Fl[i][j]) fl[i][j]=cnt++; - } the voidfuc () * { $Cnt1=cnt2=0; flag=0;Panax Notoginseng for(intI=0; i<r;i++) - { the for(intj=0; j<c;j++) + { A if((j==0|| s[i][j-1]=='*') &&s[i][j]!='*') the { +acr[++cnt1].num=Fl[i][j]; -tmp=0, flag=1; $ } $ if(s[i][j]=='*') flag=0, acr[cnt1].ans[tmp]=' /'; - if(flag) - { theacr[cnt1].ans[tmp++]=S[i][j]; - if(j==c-1) flag=0, acr[cnt1].ans[tmp]=' /';Wuyi } the } - } Wuflag=0; - for(intj=0; j<c;j++) About { $ for(intI=0; i<r;i++) - { - if((i==0|| s[i-1][j]=='*') && s[i][j]!='*') - { Adown[++cnt2].num=Fl[i][j]; +tmp=0, flag=1; the } - if(s[i][j]=='*'&&flag) flag=0, down[cnt2].ans[tmp]=' /'; $ if(flag) the { thedown[cnt2].ans[tmp++]=S[i][j]; the if(i==r-1) flag=0, down[cnt2].ans[tmp]=' /'; the } - } in } the } the intMain () About { thek=1; the while(cin>>r&&R) the { +Cin>>C; - for(intI=0; i<r;i++) cin>>S[i]; the mark ();Bayi fuc (); theSort (acr+1, acr+cnt1+1, CMP); theSort (down+1, down+cnt2+1, CMP); - if(k>1) puts (""); -printf"Puzzle #%d:\n", k++); thePuts"Across"); the if(CNT1) the for(intI=1; i<=cnt1;i++) theCOUT<<SETW (3) <<acr[i].num<<'.'<<acr[i].ans<<Endl; -Puts" Down"); the if(Cnt2) the for(intI=1; i<=cnt2;i++) theCOUT<<SETW (3) <<down[i].num<<'.'<<down[i].ans<<Endl;94 } the}
UVa 232-crossword Answers