package company.qianxin.pro1; import java.util.Scanner; /**  * @author tortoiselala  */ public class Main {     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         String line = in.nextLine();         String[] lineSpiltResult = line.split(" ");         int[] pid = new int[lineSpiltResult.length];         int idx = 0;         for (String e : lineSpiltResult) {             pid[idx++] = Integer.valueOf(e);         }         idx = 0;         line = in.nextLine();         lineSpiltResult = line.split(" ");         int[] ppid = new int[lineSpiltResult.length];         for (String e : lineSpiltResult) {             ppid[idx++] = Integer.valueOf(e);         }         int x = in.nextInt();         System.out.println((isIn(x, pid, ppid) ? 1 : 0) + compute(x, ppid, pid));     }     public static int compute(int x, int[] ppid, int[] pid) {         int re = 0;         for (int i = 0; i < ppid.length; i++) {             if (ppid[i] == x) {                 re += 1 + compute(pid[i], ppid, pid);             }         }         return re;     }     public static boolean isIn(int a, int[] pid, int[] ppid) {         for (int e : pid) {             if (a == e) {                 return true;             }         }         for (int e : ppid) {             if (a == e) {                 return true;             }         }         return false;     } } /* 3 1 5 21 10 0 3 3 1 5 3  */
点赞 3

相关推荐

牛客网
牛客企业服务