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

过了,注意换行的问题,我就为了这个PE了几次

Posted by conan614 at 2009-11-04 22:09:50 on Problem 1140
#include <iostream>
using namespace std;
int main()
{
	int a[1000];
	int b[1000];
	int result[1000];
	int number1,number2;
	int i=0;
	int j=0;
	int k=0;
	while(1)
	{
		cin>>number1;
		cin>>number2;
		if(number1==0&&number2==0)
			break;
		i=0;
		j=0;
		k=0;
		while(1)
		{
			if(i==0)
			{
				a[i]=number1/number2;
				b[i]=number1%number2;
			}
			else 
			{
				a[i]=b[i-1]*10/number2;
				b[i]=b[i-1]*10%number2;
			}
			if(b[i]==0)
			{
				cout<<".";
				for(j=1;j<=i;j++)
				{
					cout<<a[j];
					if(j%50==49&&j<i)
						cout<<endl;
				}
				cout<<endl;
				cout<<"This expansion terminates."<<endl;
				break;
			}
			for(j=0;j<i;j++)
			{
				if(b[i]==b[j])
					break;
			}
			if(j!=i)
			{
				cout<<".";
				for(k=1;k<=i;k++)
				{
					cout<<a[k];
					if(k%50==49&&k<i)
						cout<<endl;
				}
				cout<<endl;
				cout<<"The last "<<(i-j)<<" digits repeat forever."<<endl;
				break;
			}
			i++;
		}

	}
	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