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:各位同学请帮我看一下,什么地方出了问题

Posted by apolor at 2004-05-15 21:56:24 on Problem 1657
In Reply To:各位同学请帮我看一下,什么地方出了问题 Posted by:apolor at 2004-05-15 14:47:34
> #include<iostream.h>
> #include<math.h>
> 
> void main(){
> 	char x[20][8],y[20][8];
> 	int n,i,ax,ay;
> 	cin>>n;
> 	for(i=0;i<n;i++)
> 		cin>>x[i]>>y[i];
> 	for(i=0;i<n;i++){
> 		ax=abs(x[i][0]-y[i][0]);
> 		ay=abs(x[i][1]-y[i][1]);
> 		if(ax>ay)
> 			cout<<ax<<" ";
> 		else cout<<ay<<" ";
> 
> 		if(ax==ay||ax==0||ay==0)
> 			cout<<"1 ";
> 		else cout<<abs(ax-ay)+1<<" ";
> 
> 		if(ax==0||ay==0)
> 			cout<<"1 ";
> 		else cout<<"2 ";
> 		
> 		if(ax==ay) 
> 			cout<<"1 "<<endl;
> 		else cout<<"Inf "<<endl;
> 	}
> }
> 
> 提交市老是出错,是算法有问题吗?或是还有别的什么地方没有考虑到。
算法错了,看下面的:

#include<iostream.h>
#include<math.h>

void main(){
	char x[25][8],y[25][8];
	int n,i,ax,ay;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>x[i]>>y[i];
	for(i=0;i<n;i++){
		ax=abs(x[i][0]-y[i][0]);
		ay=abs(x[i][1]-y[i][1]);
		if(ax>ay)
			cout<<ax<<" ";
		else cout<<ay<<" ";

		if(ax==ay||ax==0||ay==0)
			cout<<"1 ";
		else cout<<"2 ";

		if(ax==0||ay==0)
			cout<<"1 ";
		else cout<<"2 ";
		
		if((ax+ay)%2==0)
			if(ax==ay)
				cout<<"1 "<<endl;
			else 
				cout<<"2 "<<endl;
		else cout<<"Inf "<<endl;
	}
}


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