题解 | #数据分类处理#
数据分类处理
http://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
ArrayList<Integer> iList = new ArrayList<>();
HashSet<Integer> rSet = new HashSet<>();
while(sc.hasNext()){
int ni = sc.nextInt();
for(int i=0;i<ni;i++){
int num = sc.nextInt();
iList.add(num);
}
sc.nextLine();
int nr = sc.nextInt();
for(int i=0;i<nr;i++){
int num = sc.nextInt();
rSet.add(num);
}
ArrayList<Integer> rList = new ArrayList<>(rSet);
Collections.sort(rList);
ArrayList<Integer> allList = new ArrayList<>();
for(Integer inR:rList){
ArrayList<Integer> tempList = new ArrayList<>();
tempList.add(inR);
for(int i=0;i<iList.size();i++){
int iNum = iList.get(i);
if((iNum+"").contains(inR+"")){
tempList.add(i);
tempList.add(iNum);
}
}
if(tempList.size()>1){
int count = (tempList.size()-1)/2;
tempList.add(1,count);
allList.addAll(tempList);
}else{
tempList.clear();
}
}
int totalCount = allList.size();
allList.add(0,totalCount);
for(Integer ins:allList){
System.out.print(ins+" ");
}
}
}
}
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
ArrayList<Integer> iList = new ArrayList<>();
HashSet<Integer> rSet = new HashSet<>();
while(sc.hasNext()){
int ni = sc.nextInt();
for(int i=0;i<ni;i++){
int num = sc.nextInt();
iList.add(num);
}
sc.nextLine();
int nr = sc.nextInt();
for(int i=0;i<nr;i++){
int num = sc.nextInt();
rSet.add(num);
}
ArrayList<Integer> rList = new ArrayList<>(rSet);
Collections.sort(rList);
ArrayList<Integer> allList = new ArrayList<>();
for(Integer inR:rList){
ArrayList<Integer> tempList = new ArrayList<>();
tempList.add(inR);
for(int i=0;i<iList.size();i++){
int iNum = iList.get(i);
if((iNum+"").contains(inR+"")){
tempList.add(i);
tempList.add(iNum);
}
}
if(tempList.size()>1){
int count = (tempList.size()-1)/2;
tempList.add(1,count);
allList.addAll(tempList);
}else{
tempList.clear();
}
}
int totalCount = allList.size();
allList.add(0,totalCount);
for(Integer ins:allList){
System.out.print(ins+" ");
}
}
}
}