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
北京大学《ACM/ICPC大学生程序设计竞赛训练》暑期课面向全球招生!

Re:奇妙的runtime error了,求达人指点

Posted by 737363395 at 2014-09-18 00:34:01 on Problem 1330
In Reply To:奇妙的runtime error了,求达人指点 Posted by:834208094 at 2012-05-12 00:34:48
> import java.io.File;
> import java.io.FileNotFoundException;
> import java.util.ArrayList;
> import java.util.Scanner;
> 
> public class Main {
> 
> 	public static void getFather(ArrayList Father, ArrayList Child, int child, ArrayList FATHERS) {
>  		int index = Child.indexOf(child + "");
> 		FATHERS.add(child + "");
> 		while(index >= 0) {
> 			FATHERS.add(Father.get(index));
> 			index = Child.indexOf(Father.get(index));
> 		}
> 	}
> 	
> 	public static void main(String args[]) {
> 		Scanner sc = new Scanner(System.in);
> 		String s = sc.nextLine();
> 		int firstline = Integer.parseInt(s);
> 		for(int i=0; i<firstline; i++) {
> 			ArrayList al1 = new ArrayList();
> 			ArrayList al2 = new ArrayList();
> 			ArrayList al3 = new ArrayList();
> 			ArrayList al4 = new ArrayList();
> 			String S = sc.nextLine();
> 			int secondline = Integer.parseInt(S);
> 			for(int k=0; k<secondline-1; k++) {
> 				String lines = sc.nextLine();
> 				al1.add(lines.split(" ")[0]);
> 				al2.add(lines.split(" ")[1]);
> 			}
> 			String string = sc.nextLine();
> 			getFather(al1, al2, Integer.parseInt((string.split(" ")[0])), al3);
> 			getFather(al1, al2, Integer.parseInt((string.split(" ")[1])), al4);
> 			outer:
> 			for(int I=0; I<al3.size(); I++) {
> 				for(int K=0; K<al4.size(); K++) {
> 					int numal3 =  Integer.parseInt((String)al3.get(I));
> 					int numal4 =   Integer.parseInt(((String)al4.get(K)));
> 					if(numal3 == numal4) {
> 						System.out.println(al3.get(I));
> 						break outer;
> 					}
> 				}
> 			}
> 		}
> 	}
> }
原数据第一组试一下1 8的lca
我就在这里错的

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