#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;intrr,cc;Chars[ -][ -];intnum[ -][ -];BOOLBorderintXinty) { if(x>=0&&x<rr&&y>=0&&Y<CC)return true; return false;}intmove[2][2]={{0,-1},{-1,0}};BOOLCheckintXinty) { if(s[x][y]=='*')return false; for(intI=0;i<2;++i) { inttx=x+move[i][0]; intty=y+move[i][1]; if(!border (Tx,ty))return true; if(s[tx][ty]=='*')return true; } return false;}Charb[ $][ $];Charc[ $][ $];Chartemp[ $];intb[ $],c[ $];intMain () {intcas=0; while(SCANF ("%d",&RR) {memset (num,0,sizeof(num)); if(CAS) printf ("\ n"); scanf ("%d",&cc); inti,j,y=0; for(i=0; i<rr;++i) {scanf ("%s", S[i]); } for(i=0; i<rr;++i) { for(j=0; j<cc;++j) { if(check (i,j)) {Num[i][j]=++y; } } } intp=0, q=0; for(i=0; i<rr;++i) { intk=0; for(j=0; j<cc;++j) { //printf ("S%d%d:%c check:%d\n", I,j,s[i][j],check (I,j)); if(Num[i][j]) {b[p][k++]=S[i][j]; if(k==1) b[p]=Num[i][j]; intt=j+1; while(t<cc&&s[i][t]!='*') {b[p][k++]=S[i][t]; T++; } B[p][k]=' /'; P++;k=0; J=T; } } } for(j=0; j<cc;++j) { intk=0; for(i=0; i<rr;++i) { if(Num[i][j]) {c[q][k++]=S[i][j]; if(k==1) c[q]=Num[i][j]; intt=i+1; while(t<rr&&s[t][j]!='*') {c[q][k++]=S[t][j]; T++; } C[q][k]=' /'; Q++;k=0; I=T; }}} printf ("Puzzle #%d:\n",++CAs); printf ("across\n"); for(i=0; i<p;++i) {printf ("%3d.%s\n", B[i],b[i]); } printf ("down\n"); for(i=0; i<q;++i) { for(j=0; j<q-1;++j) { if(c[j+1]<C[j]) {Swap (C[j+1],c[j]); intCnt=0; intlen1=strlen (C[j]); intLen2=strlen (c[j+1]); for(p=0;p <len1;++p) {temp[cnt++]=C[j][p]; } temp[cnt]=' /'; CNT=0; for(p=0;p <len2;++p) {c[j][cnt++]=c[j+1][p]; } c[j][cnt]=' /'; CNT=0; for(p=0;p <len1;++p) {C[j+1][cnt++]=Temp[p]; } c[j+1][cnt]=' /'; } } } for(i=0; i<q;++i) {printf ("%3d.%s\n", C[i],c[i]); } } return 0;}
There are several points to note in this question. First.. The string ends with '/'. Do not open decimal groups.
Second-aligned output format: A careful comparison will reveal that%3d
While loop inside t forget + +
The meaning of Word in the down list is understood incorrectly: The label still uses the first cursor
The down list needs to be output from small to large. I bubbled up a bit.
The NUM array that stores the labels is memset every time
After the record, K remember to return to zero
There must be a blank line between the two output.
There are no blank lines after the last output
Caution Array out of bounds:
If the data is very large: And.. A single letter is an output:
Then we b[20][20] obviously not enough.
Definitely more than 20. The C array is also ... This problem is mainly wrong in the investigation
This place.
We can also look for the side output.
But how to deal with the C array ...
UVA232 string Processing