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 |
类似的程序怎么超时了呢?In Reply To:为什么会Runtime Error呢?我的数组已经开的够大的了啊! Posted by:zhujie at 2006-03-10 15:36:48 #include<stdio.h> #include<string.h> char value[26]={2,5,4,4,1,6,5,5,1,7,6,3,5,2,3,5,7,2,1,2,4,6,6,7,5,7}; char len1,len2; int ok=0; char str1[20],str2[20]; int bit[26],bit1[26]; int right(char str2[]){ int i; if (len2>len1) return 0; for (i=0;i<26;i++) bit1[i]=bit[i]; for (i=0;i<len2;i++) if (bit1[str2[i]-'a']==0) return 0; else bit1[str2[i]-'a']--; if (len1==len2) ok=1; return 1; } int solve(char str2[]){ int sum=0; int i; for (i=0;i<len2;i++){ sum=sum+value[str2[i]-'a']; } return sum; } void main(){ char st[40000][10]; int score,res=0; int k=0; int i,j; scanf("%s",str1); len1=strlen(str1); for (i=0;i<26;i++) bit[i]=0; for (i=0;i<len1;i++) bit[str1[i]-'a']++; scanf("%s",str2); while(strcmp(str2,".")!=0){ if (ok){ scanf("%s",str2); continue; } len2=strlen(str2); if (right(str2)){ score=solve(str2); if (score>res){ res=score; } } if ((len1==7)&&(len2<5)||(len1==6)&&(len2<4)){ strcpy(st[k],str2); k++; } scanf("%s",str2); } if(ok) goto end; for (i=0;i<k-1;i++) for (j=i+1;j<k;j++){ strcpy(str2,st[i]); strcat(str2,st[j]); len2=strlen(str2); if (right(str2)){ score=solve(str2); if (score>res) res=score; if (ok) goto end; } } end:printf("%d\n",res); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator