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 |
Re:怎么输入才更快?我那样行吗,初问?In Reply To:TLE!!!怎么做呢?帮我看看吧 Posted by:xiaol at 2005-10-23 12:54:35 > #include <stdio.h> > #include <string.h> > int a[50000]; > char s[50000][8]; > void output(int i,int j) { > int max=-1,k,p; > if(i==j) { > printf("(%s/%d)",s[i],a[i]); > return ; > } > for(k=i;k<=j;k++) { > if(a[k]>max) { > max=a[k]; > p=k; > } > } > if(p==i) { > printf("("); > printf("%s/%d",s[p],a[p]); > output(i+1,j); > printf(")"); > return ; > } > if(p==j) { > printf("("); > output(i,j-1); > printf("%s/%d",s[p],a[p]); > printf(")"); > return ; > } > printf("("); > output(i,p-1); > printf("%s/%d",s[p],a[p]); > output(p+1,j); > printf(")"); > return ; > } > int main(){ > int n,i,j,k; > char c; > int tem,len; > int max,p; > while(1){ > scanf("%d",&n); > if(n==0) break; > max=-1; > if(n==1) { > scanf("%s",&c,&s[0]); > printf("(%s)\n",s[0]); > continue; > } > for(i=0;i<n;i++) { > scanf("%s",s[i]); > len=strlen(s[i]); > j=len-1; > k=1;tem=0; > while(s[i][j]>='0' && s[i][j]<='9'){ > tem=tem+(s[i][j]-'0')*k; > k=k*10; > j--; > } > a[i]=tem; > s[i][j]='\0'; > if(max<a[i]) { > max=a[i]; > p=i; > } > } > if(p==0) { > printf("("); > printf("%s/%d",s[p],a[p]); > output(p+1,n-1); > printf(")\n"); > continue; > } > if(p==n-1) { > printf("("); > output(0,p-1); > printf("%s/%d",s[p],a[p]); > printf(")\n"); > continue; > } > printf("("); > output(0,p-1); > printf("%s/%d",s[p],a[p]); > output(p+1,n-1); > printf(")\n"); > } > return 0; > } > Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator