| ||||||||||
| 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 | |||||||||
Re:奇妙的runtime error了,求达人指点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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator