题解 | #数据分类处理#
数据分类处理
http://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd
//挺麻烦的一道题,做了两个小时
import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=null;
while((s=br.readLine())!=null){
String s1=br.readLine();
String str2[]=s1.split(" ");
int a2[]=new int[str2.length-1];
for(int i=1;i<str2.length;i++){
a2[i-1]=Integer.valueOf(str2[i]);
}
int R=Integer.valueOf(str2[0]);
String str1[]=s.split(" ");
String a1[]=new String[str1.length-1];
for(int i=1;i<str1.length;i++){
a1[i-1]=str1[i];
}
int I=Integer.valueOf(str1[0]);
Arrays.sort(a2);
Set<Integer> set=new LinkedHashSet<Integer>();
for(int i=0;i<a2.length;i++){
set.add(a2[i]);
}
String[] str3=new String[set.size()];
int l=0;
for(Integer scale:set){
str3[l]=String.valueOf(scale);
l++;
}
StringBuilder sb=new StringBuilder();
int count1=0;
for(int i=0;i<str3.length;i++){
int count=0;
for(int j=0;j<I;j++){
if(a1[j].contains(str3[i])){
count++;
}
}
if(count!=0) {
sb.append(str3[i]+" ");
sb.append(count+" ");
count1=count1+2;
}//sb.insert(sb.length()-count,count+" ");
for(int j=0;j<I;j++){
if(a1[j].contains(str3[i])){
sb.append(j+" "+a1[j]+" ");
count1=count1+2;
}
}
}
sb.insert(0,count1+" ");
char[] chars=s.toCharArray();
System.out.println(sb);
}
}
}