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

终于过了!!粘我的代码,让后来者少走弯路啊!

Posted by bjtu1 at 2008-08-17 09:57:40 on Problem 1657
#include<stdio.h>
#include<math.h>

int max(int a,int b){
	return a>b?a:b;
};


int main()
{
	int n,flag,i;
	char str[100],str1[100];
	int n1,n2,n3,n4;
	int dist1,dist2;

	scanf("%d",&n);
		for(i=1;i<=n;i++){
			flag=0;
			scanf("%s %s",&str,&str1);
			dist1=abs(str[0]-str1[0]);
			dist2=abs(str[1]-str1[1]);

			if(dist1==0&&dist2==0)
				n1=n2=n3=n4=0;
			else if(dist1==dist2){
					n1=dist1;
					n2=1;
					n3=2;
					n4=1;
				}
			else if(dist1==0&&dist2%2!=0){
				n1=dist2;
				n2=1;
				n3=1;
				flag=1;
			}
			else if(dist1==0&&dist2%2==0){
				n1=dist2;
				n2=1;
				n3=1;
				n4=2;;
			}
			else if(dist2==0&&dist1%2!=0){
				n1=dist2;
				n2=1;
				n3=1;
				flag=1;
			}
			else if(dist2==0&&dist1==0){
				n1=dist2;
				n2=1;
				n3=1;
				n4=2;
			}
			else if((dist1%2==0&&dist2%2==0)||(dist1%2!=0&&dist2%2!=0)){
				n1=max(dist1,dist2);
				n2=2;
				n3=2;
				n4=2;
			}

			if(flag)
				printf("%d %d %d Inf\n",n1,n2,n3);
			else
				printf("%d %d %d %d\n",n1,n2,n3,n4);
		}
	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