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 |
为什么这种方法过不了。。。什么数据都试过了啊 .....#include<stdio.h> #include<string.h> #include<stdlib.h> char str[1010]; int main() { int i,j,n,k,h[10]; int sum; while(scanf("%s",str),str[0]!='-') { memset(h,0,sizeof(h)); int l=strlen(str); if(l==1) { printf("1%s\n",str); continue; } sum=0; for(i=0;i<l;i++) { sum=sum*10+str[i]-'0'; if(sum>1000) { for(j=9;j>=2;j--) { if(sum%j==0) while(sum%j==0) { h[j]++; sum/=j; } if(sum==0) break; } } } for(j=9;j>=2;j--) { while(sum%j==0) { h[j]++; sum/=j; if(sum==0) break; } } if(sum>=10) { printf("There is no such number.\n"); continue; } h[8]+=h[2]/3; h[2]=h[2]%3; if(h[2]>h[3]&&h[3]!=0) { h[6]+=h[3]; h[2]-=h[3];h[3]=0; } else if(h[2]<h[3]&&h[2]!=0) { h[6]+=h[2]; h[3]-=h[2]; h[2]=0; } else if(h[2]==h[3]&&h[2]!=0) { h[6]+=h[3]; h[3]=0;h[2]=0; } h[9]+=h[3]/2; h[3]=h[3]%2; h[4]+=h[2]/2; h[2]=h[2]%2; for(i=1;i<=9;i++) { if(h[i]!=0) { while(h[i]--) printf("%d",i); } } 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