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

Re:if(a/b<=2)和if(a<=2*b)有什么不同

Posted by zhubingn at 2012-08-13 11:57:47 on Problem 2348
In Reply To:if(a/b<=2)和if(a<=2*b)有什么不同 Posted by:caolq at 2010-01-17 15:22:31
> AC的代码
> #include<stdio.h>
> int main()
> {
> 	int a,b,t,k;
> 	while(scanf("%d%d",&a,&b)&&(a!=0||b!=0))
> 	{
> 		if(a<b)
> 		{
> 			t=a;
> 			a=b;
> 			b=t;
> 		}
> 		if(a/b>=2||a%b==0)
> 			printf("Stan wins\n");
> 		else
> 		{
> 			k=0;
> 			while(a/b<2)
> 			{
> 				t=a;
> 				a=b;
> 				b=t-b;
> 				k++;
> 			}
> 			if(k%2)
> 				printf("Ollie wins\n");
> 			else
> 				printf("Stan wins\n");
> 		}
> 	}
> 	return 0;
> }
> WA的代码
> #include<stdio.h>
> int main()
> {
> 	int a,b,t,k;
> 	while(scanf("%d%d",&a,&b)&&(a!=0||b!=0))
> 	{
> 		if(a<b)
> 		{
> 			t=a;
> 			a=b;
> 			b=t;
> 		}
> 		if(a>=2*b||a%b==0)
> 			printf("Stan wins\n");
> 		else
> 		{
> 			k=0;
> 			while(a<2*b)
> 			{
> 				t=a;
> 				a=b;
> 				b=t-b;
> 				k++;
> 			}
> 			if(k%2)
> 				printf("Ollie wins\n");
> 			else
> 				printf("Stan wins\n");
> 		}
> 	}
> 	return 0;
> }
> 
> 
> 难道2*b超出数据范围

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