Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么是WA。。。。。。。。。请高手指教啊!

Posted by qpwoei at 2007-03-30 23:31:14 on Problem 1140
#include<iostream>
using namespace std;


int G(int n,int m) //m为大数,n为小数,函数为判断最小公约数
{
 if(n==0)return m;
 else G(m%n,n);
}

int main()
{
 int a[1000],b[1000];
 int m,n,i,k,Flat,F;
 
	
	
	while(cin>>m>>n)
	{
	 
		Flat=0;
		if(m==0&&n==0)break;
		if(m==0)
		{
		 cout<<".0"<<endl;
		cout<<"This expansion terminates."<<endl;	
		continue;
		}
	    for(i=0;i<1000;i++)
		{a[i]=-1;b[i]=-1;}
       
		i=G(m,n);
		m/=i;
        n/=i;
        F=0;

		b[0]=m;
	    i=0;
	    while(1)
		{
		 m=m*10;
	     if((m%n==0)&&(m/n==0)){Flat=1;break;}
		 a[i]=m/n;	    	  
	     m%=n;
    	 for(k=0;k<i;k++)            //检查
			 if(m==b[k]){F=1;break;}
         if(F==1)break;
		 b[i+1]=m;
	     i++;
	
		}
	    m=0;
	    cout<<".";
		while(a[m]!=-1)
		 {
		 cout<<a[m];m++;}
	     cout<<endl;
	 if(Flat==0)cout<<"The last "<<i-k+1<<" digits repeat forever."<<endl;	  
	 else cout<<"This expansion terminates."<<endl;

	}
return 0;

}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator