importjava.util.Scanner;publicclassMain{publicstaticMap<Character,Integer> map =newHashMap();publicstaticvoidmain(String[] args){Scanner sc =newScanner(System.in);while(sc.hasNextLine()){String s = sc.nextLine();String[] ss = s.split(" ");String pre = ss[0];String in = ss[1];// 构建⼆叉树TreeNode res =afterHelper(pre.toCharArray(), in.toCharArray());//打印⼆叉树printTree(res);System.out.println();}}publicstaticvoidprintTree(TreeNode root){if(root ==null)return;printTree(root.left);printTree(root.right);System.out.print(root.val);}}
importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[] args){Scanner scanner =newScanner(System.in);while(scanner.hasNextLine()){String line = scanner.nextLine();String[] s = line.split(" ");String x = s[0];String y = s[1];int m = x.length();int n = y.length();// 初始化dp数组int[][] dp =newint[m +1][n +1];//...// 输出int max = dp[m][n];System.out.println(max);}}}
20、多组测试数据,每组第一行为两个正整数n和m,接下来m行,每行3个整数, 最后一行两个整数。
C++
intmain(){int n, m;while(cin >> n >> m){// 构建图while(m--){int a, b, l;
cin >> a >> b >> l
}int x, y;
cin >> x >> y;}return0;}
Java
importjava.util.Arrays;importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[] args){Scanner scanner =newScanner(System.in);while(scanner.hasNext()){// 处理输⼊int n = scanner.nextInt();int m = scanner.nextInt();for(int i =0; i < m; i++){int a = scanner.nextInt();int b = scanner.nextInt();int l = scanner.nextInt();}int x = scanner.nextInt();int y = scanner.nextInt();// 处理输出int res =dfs(graph, x, y, isVisit, sum);if(res !=Integer.MAX_VALUE){System.out.println(res);}else{System.out.println("No path");}}}privatestaticintdfs(int[][] graph,int start,int end,int[] isVisit,int sum){if(end == start){return sum;}return min;}}