Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
奇妙的runtime error了,求达人指点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; } } } } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator