import java.util.Scanner; import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int iSize = scan.nextInt(); List<integer> l_I = new ArrayList<>(); Set<integer> l_R = new TreeSet<>(); for (int i = 0; i < iSize; i++) { l_I.add(scan.nextInt()); } int r_size = scan.nextInt(); for (int i = 0; i < r_size; i++) { l_R.add(scan.nextInt()); } StringBuilder resData = new StringBuilder(); for (Integer integer : l_R) { StringBuilder stringBuilder = new StringBuilder(); int index = 0; //记录R元素出现的位置 for (Integer i : l_I) { if (i.toString().contains(integer.toString())) { stringBuilder.append(index).append(" ").append(i).append(" "); } index++; } if (!stringBuilder.toString().equals("")) { resData.append(integer).append(" ").append(stringBuilder.toString().split(" ").length/2).append(" ").append(stringBuilder); } } String res = resData.toString().split(" ").length + " " + resData; System.out.println(res); } }</integer></integer>
点赞

相关推荐

牛客网
牛客企业服务