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 |
这题怎么会表达错误?!在UVA上通过了的,只是多一个空白行#include<iostream.h> int com(int a,int b) { int temp; while(a%b!=0) { temp=b; b=a-a/b*b; a=temp; } return b; } int fac2(int &a) { int cnt=0; while(a%2==0) { cnt++; a/=2; } return cnt; } int fac5(int &a) { int cnt=0; while(a%5==0) { cnt++; a/=5; } return cnt; } int hmb(int a) { if(a==0) return 0; else if (1<=a&&a<10) return 1; else if(10<=a&&a<100) return 2; else if(100<=a&&a<1000) return 3; else if(1000<=a&&a<10000) return 4; else if(10000<=a&&a<100000) return 5; else return 6; } void main() { int m,n,c,c2,c5,quo[1000],rep[1000],i,j,pnt,urep,rm,cp; bool dflag; cin>>m>>n; while(n!=0) { dflag=true; c=com(m,n); m/=c; n/=c; c2=fac2(n); c5=fac5(n); if(n==1) { dflag=false; if(c2>=c5) { pnt=c2; for(i=0;i<c2-c5;i++) m*=5; } else { pnt=c5; for(i=0;i<c5-c2;i++) m*=2; } i=pnt-hmb(m); cout<<"."; for(j=0;j<i;j++) cout<<"0"; cout<<m<<endl<<"This expansion terminates."<<endl; } else if(c2==c5) pnt=c2; else if(c2>c5) { pnt=c2; for(i=0;i<c2-c5;i++) m*=5; } else { pnt=c5; for(i=0;i<c5-c2;i++) m*=2; } if(dflag) { urep=m/n; m=m%n; i=j=rm=0; do { quo[i]=(9+10*rm)/n; rm=(9+10*rm)%n; i++; } while(rm!=0); while(i>0) { rep[j]=(m*quo[i-1]+rm)%10; rm=(m*quo[i-1]+rm)/10; j++; i--; } while(rm>0) { rep[j]=rm%10; rm/=10; j++; } cp=1; cout<<"."; for(i=0;i<pnt-hmb(urep);i++) { cout<<"0"; cp++; } if(urep!=0) { cout<<urep; cp+=hmb(urep); } for(i=j-1;i>=0;i--) { cout<<rep[i]; cp++; if(cp==50) { cp=0; cout<<endl; } } cout<<endl<<"The last "<<j<<" digits repeat forever."<<endl; } cin>>m>>n; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator