Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
yun...我调了一下午了,怎么还是wa....有BT的数据没?#include <stdio.h> #include <string.h> typedef struct { char st[128]; }Node; Node s[128][16]; int col[16]; bool isCMD(char ch) { if(ch=='*'||ch=='<'||ch=='>'||ch=='=') return true; return false; } int main() { int i,j,k,m,ft,sum,len,pos,px,ls,tlen,pre; char cmd[128],str[128][128]; gets(cmd); i=0; while(1) { len=strlen(cmd); gets(str[i]); if(isCMD(str[i][0])) { for(j=0;j<i;j++) { pre=-1; px=0; while(1) { for(pos=0,k=pre+1;str[j][k]&&str[j][k]!='&';k++) s[j][px].st[pos++]=str[j][k]; s[j][px].st[pos]='\0'; if(pos>col[px]) col[px]=pos; pre=k; px++; if(str[j][k]=='\0') break; } } printf("@"); for(sum=j=0;j<len;sum+=col[j],j++); sum+=3*len-1; for(j=0;j<sum;printf("-"),j++); printf("@\n|"); for(j=0;j<len;j++) { tlen=strlen(s[0][j].st); if(cmd[j]=='<') { printf(" %s",s[0][j].st); ls=col[j]-tlen+1; for(k=0;k<ls;printf(" "),k++); } else if(cmd[j]=='=') { ft=col[j]-tlen+2; if(ft%2) { ft=(ft-1)/2; for(k=0;k<ft;printf(" "),k++); printf("%s",s[0][j].st); for(k=0;k<=ft;printf(" "),k++); } else { ft>>=1; for(k=0;k<ft;printf(" "),k++); printf("%s",s[0][j].st); for(k=0;k<ft;printf(" "),k++); } } else { ft=col[j]+1-tlen; for(k=0;k<ft;printf(" "),k++); printf("%s ",s[0][j].st); } printf("|"); } printf("\n"); if(i>1) { printf("|"); for(j=0;j<len;j++) { for(k=0;k<col[j]+2;printf("-"),k++); if(j<len-1) printf("+"); else printf("|\n"); } } for(j=1;j<i;j++) { printf("|"); for(k=0;k<len;k++) { tlen=strlen(s[j][k].st); if(cmd[k]=='<') { printf(" %s",s[j][k].st); ls=col[k]-tlen+1; for(m=0;m<ls;printf(" "),m++); } else if(cmd[k]=='>') { ft=col[k]+1-tlen; for(m=0;m<ft;printf(" "),m++); printf("%s ",s[j][k].st); } else { ft=col[k]-tlen+2; if(ft%2) { ft=(ft-1)/2; for(m=0;m<ft;printf(" "),m++); printf("%s",s[j][k].st); for(m=0;m<=ft;printf(" "),m++); } else { ft>>=1; for(m=0;m<ft;printf(" "),m++); printf("%s",s[j][k].st); for(m=0;m<ft;printf(" "),m++); } } printf("|"); } printf("\n"); } printf("@"); for(j=0;j<sum;printf("-"),j++); printf("@\n"); if(strcmp(str[i],"*")==0) return 0; strcpy(cmd,str[i]); memset(col,0,sizeof(col)); i=-1; } i++; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator