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

我用JAVA编的这道题目,怎么出现超时啊,大侠帮忙看下

Posted by 2004369701 at 2008-10-22 21:05:41 on Problem 1657
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args)throws Exception {
		
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		for(int i=0;i<n;i++){
			Scanner my=new Scanner(System.in);
			char a[]=my.next().toCharArray();
			char b[]=my.next().toCharArray();
			int x,y;
			x=Math.abs(a[0]-b[0]);
			y=Math.abs(a[1]-b[1]);
			if(x==0&&y==0)System.out.println("0 0 0 0");
			else
			{
				if(x<y)System.out.print(y);
				else System.out.print(x);
				if(x==y||x==0||y==0)System.out.print(" "+1);
				else System.out.print(" "+2);
				if(x==0||y==0)System.out.print(" "+1);
				else System.out.print(" "+2);
				if(Math.abs(x-y)%2!=0)System.out.println(" Inf");
				else if(x==y)System.out.println(" "+1);
				else System.out.println(" "+2);
				
			}
		}
			
		
	}

}

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