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 |
高精度写的我郁闷,虽然ac了,但是感觉不爽,高手帮忙看看我哪里写的不好:char * mult(const char *sl,const char *sr){ // cout<<sl<<" "<<sr<<endl; int len1=strlen(sl); int len2=strlen(sr); int i,j,k; int ms[INF]; memset(ms,0,INF); for(i=len1-1;i>=0;i--){ for(j=len2-1;j>=0;j--){ int cp1=sl[i]-'0'; int cp2=sr[j]-'0'; // cout<<cp1<<cp2<<endl; int curpos=len1-1-i+len2-1-j; // cout<<curpos<<endl; ms[curpos]+=cp1*cp2; // cout<<ms[curpos]<<endl; } } for(i=0;i<len1+len2+10;i++){ if(ms[i]>=10){ int up=ms[i]/10; ms[i]=ms[i]%10; ms[i+1]+=up; } } /* for(i=len1+len2+5;i>=0;i--){ cout<<ms[i]<<" "; } cout<<endl; */ char *ans=new char[INF]; int an=0; bool first=false; for(i=len1+len2+5;i>=0;i--){ if(!first){ if(ms[i]==0)continue; ans[an++]='0'+ms[i]; first=true; }else{ ans[an++]='0'+ms[i]; } } ans[an]='\0'; // cout<<strlen(ans)<<endl; return ans; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator