题解 | #数据分类处理#
数据分类处理
https://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd?tpId=37&tags=&title=&difficulty=0&judgeStatus=0&rp=1&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D37%26type%3D37
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int []l = new int[n];
for (int i = 0; i < n; i++) {
l[i] = in.nextInt();
}
int m = in.nextInt();
Set<Integer> set = new TreeSet<>();
for (int i = 0; i < m; i++) {
set.add(in.nextInt());
}
List<Integer> list = new ArrayList<>();
set.forEach(o-> {
List<Integer> res = getSame(o, l);
if (res.size() != 0) {
list.add(o);
list.add(res.size() / 2);
list.addAll(res);
}
});
System.out.print(list.size() + " ");
for (int i = 0; i < list.size(); i++) {
System.out.print(list.get(i) + " ");
}
}
public static List<Integer> getSame(int n, int []l) {
String s = String.valueOf(n);
List<Integer> list = new ArrayList<>();
for (int i = 0; i < l.length; i++) {
String str = String.valueOf(l[i]);
if (str.indexOf(s) >= 0) {
list.add(i);
list.add(l[i]);
}
}
return list;
}
}