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,不知要修改哪里,help~~

Posted by pmfsakula at 2005-03-27 22:26:32 on Problem 2348
//第一次自己写的,现在是WA,不知要修改哪里,help~~
//2348 Problem J:Euclid's Game
#include<iostream.h>

void swap(int &a,int &b)
{
	int c=a;
	a=b;
	b=c;
}

int gcd(int a,int b)
{
	if(0==a)return b;
	if(0==b)return a;
	if(a>b)swap(a,b);
	int c,i(0);
	for(c=a%b;c>0;c=a%b){//求最大公约数的算法-Euclid (& stein)
		a=b;
		b=c;
		i++;}
	return i;
}

int main()
{
	int a[1000],b[1000],re[1000],i=0;

	while(cin>>a[i]>>b[i]){//输入n排数
		if((a[i]==0 && b[i]==0)||cin.eof())break;//细节不知是否如此处理
		re[i]=gcd(a[i],b[i]);
		i++;
	}
	int count=i;
		
	for(i=0;i<count;i++){//输出答案
		int kw=re[i]%2;
		if(kw==0) cout<<"Ollie wins"<<endl;
		else cout<<"Stan wins"<<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