信息社会,有海量的数据需要分析处理,比如公安局分析身份证号码、QQ 用户、手机号码、银行帐号等信息及活动记录。采集输入大数据和分类规则,通过大数据分类处理程序,将大数据分类输出。
信息社会,有海量的数据需要分析处理,比如公安局分析身份证号码、QQ 用户、手机号码、银行帐号等信息及活动记录。采集输入大数据和分类规则,通过大数据分类处理程序,将大数据分类输出。
第一行先输入一个整数
代表数据集
中的数据条数。随后,在同一行输出
个整数
代表数据。
第二行先输入一个整数
代表分类规则集
中的规则条数。随后,在同一行输出
个整数
代表规则。
在一行上:
先输出一个整数
,代表一共需要输出的数字个数。简单地说,这个数字为下文中你输出数量的个数统计。
随后,对于规范后的每一条规则,如果其有效:先输出这条规则本身,随后输出一个整数
,代表符合该规则的数据条数;随后输出
个二元组
,代表符合这条规则的数据在
中的位置、数据本身。其中,位置从
开始计数。如果其无效,则跳过这条规则。
15 123 456 786 453 46 7 5 3 665 453456 745 456 786 453 123 5 6 3 6 3 0
30 3 6 0 123 3 453 7 3 9 453456 13 453 14 123 6 7 1 456 2 786 4 46 8 665 9 453456 11 456 12 786
在这组样例中,给定的原始数据集为
,给定的原始规则集为
。
规范化后的规则集为
。
随后,对
进行分类处理:
对于规则
,由于
中不存在以
为连续子串的数据,因此该规则无效,跳过;
对于规则
,
中以
为连续子串的数据有:
、
、
、
、
、
,因此该规则有效。根据输出描述,先输出规则本身
、随后输出符合要求的条数
、随后输出符合要求的数据在
中的位置和整数本身
;
对于规则
,
中以
为连续子串的数据有:
、
、
、
、
、
、
,因此该规则有效。根据输出描述,先输出规则本身
、随后输出符合要求的条数
、随后输出符合要求的数据在
中的位置和整数本身。
不要忘了在输出开始的整数
,在这个样例中,一共输出了
个数字,所以
。
本题由牛客重构过题面,您可能想要阅读原始题面,我们一并附于此处。
【以下为原始题面】
从R依次中取出R<i>,对I进行处理,找到满足条件的I:
I整数对应的数字需要连续包含R<i>对应的数字。比如R<i>为23,I为231,那么I包含了R<i>,条件满足 。
按R<i>从小到大的顺序:
(1)先输出R<i>;
(2)再输出满足条件的I的个数;
(3)然后输出满足条件的I在I序列中的位置索引(从0开始);
(4)最后再输出I。
附加条件:
(1)R<i>需要从小到大排序。相同的R<i>只需要输出索引小的以及满足条件的I,索引大的需要过滤掉
(2)如果没有满足条件的I,对应的R<i>不用输出
(3)最后需要在输出序列的第一个整数位置记录后续整数序列的个数(不包含“个数”本身)
序列I:15,123,456,786,453,46,7,5,3,665,453456,745,456,786,453,123(第一个15表明后续有15个整数)
序列R:5,6,3,6,3,0(第一个5表明后续有5个整数)
输出:30, 3,6,0,123,3,453,7,3,9,453456,13,453,14,123,6,7,1,456,2,786,4,46,8,665,9,453456,11,456,12,786
说明:
30----后续有30个整数
3----从小到大排序,第一个R<i>为0,但没有满足条件的I,不输出0,而下一个R<i>是3
6--- 存在6个包含3的I
0--- 123所在的原序号为0
123--- 123包含3,满足条件
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) { // 注意 while 处理多个 case
String totalDataNumAndDataDetail = in.nextLine();
String[] totalDataNumAndDataDetails = totalDataNumAndDataDetail.split(" ");
HashMap<Integer, String> dataDetail = new HashMap<>();
for (int i = 1; i < totalDataNumAndDataDetails.length; i++) {
dataDetail.put(i - 1, totalDataNumAndDataDetails[i]);
}
int dataSum = Integer.valueOf(totalDataNumAndDataDetails[0]);
String[] rules = in.nextLine().split(" ");
TreeSet<String> ruleSet = new TreeSet<>(new Comparator<String>(){
public int compare(String o1, String o2){
return Integer.valueOf(o1).compareTo(Integer.valueOf(o2));
}
});
for (int i = 1; i < rules.length; i++) {
ruleSet.add(rules[i]);
}
int res = 0;
TreeSet<String> temp = new TreeSet<>(ruleSet);
List<Integer> eachRuleNum = new ArrayList<>();
for (String rule : temp) {
int len = totalDataNumAndDataDetails[0].length();
String newtotalDataNumAndDataDetail = totalDataNumAndDataDetail.substring(len);
if (!newtotalDataNumAndDataDetail.contains(rule)) {
ruleSet.remove(rule);
continue;
} else {
int nowRes = 0;
for (int i = 1; i < totalDataNumAndDataDetails.length; i++) {
String t = totalDataNumAndDataDetails[i];
if (t.contains(rule)) {
nowRes++;
}
}
res += nowRes;
eachRuleNum.add(nowRes);
}
}
System.out.print((2 * res + ruleSet.size() + eachRuleNum.size()) + " ");
int index = 0;
for (String rule : ruleSet) {
System.out.print(rule + " " + eachRuleNum.get(index++) + " ");
for (Integer key : dataDetail.keySet()) {
if (dataDetail.get(key).contains(rule)) {
System.out.print(key + " " + dataDetail.get(key) + " ");
}
}
}
}
}
} import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
// 注意 while 处理多个 case
int n = in.nextInt();
List<Integer> I = new ArrayList<>();
for (int i = 0;i < n; i++){//输入数据
I.add(in.nextInt());
}
int m = in.nextInt();
Set<Integer> R = new HashSet<Integer>();
for (int i = 0;i < m; i++){//输入规则并使用set特性去重
R.add(in.nextInt());
}
Integer[] r = new Integer[R.size()];
R.toArray(r);
Arrays.sort(r);//规则排序
int count = 0;//输出计数
StringBuilder sb = new StringBuilder();
for(int i = 0;i<r.length;i++){//根据规则遍历
int countRule= 0;//规则计数
String ruleStr = String.valueOf(r[i]);//取规则
List<Integer> num = new ArrayList<>();
for (int j = 0; j < I.size(); j++){
//if ((I.get(j)+"").indexOf(r[i]+"") != -1){//判断当前数据中是否包含连续的规则
String numStr = String.valueOf(I.get(j));//获取当前数据
if(numStr.contains(ruleStr)){
countRule++;//包含则规则计数增加
num.add(j);//并且记录此数据在数据列表中的位置
}
}
if (countRule!=0){//如果规则匹配成功
sb.append(r[i]+" "+countRule+" ");//将规则和规则匹配的次数添加到输出结果中
for (int j = 0;j <num.size();j++){
//将所有符合当前规则的数据添加到输出结果中
sb.append(num.get(j)+" "+I.get(num.get(j))+" ");
}
}
}
//计算输出的次数,以" "为分割计数
count = sb.toString().split(" ").length;
System.out.println(count+" "+sb);//输出结果
/*
System.out.print("I:");
for (int i : I){
System.out.print(i);
System.out.print(" ");
}
System.out.print("r:");
for (int i : r){
System.out.print(i);
System.out.print(" ");
} */
// System.out.println();
in.close();
}
} package com.hw.nk;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;
public class Test25 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int no1 = sc.nextInt();
int[] arr1 = new int[no1];
for (int i = 0; i < no1; i++) {
arr1[i]=sc.nextInt();
}
TreeSet<Integer> rule = new TreeSet();
int no2 = sc.nextInt();
for (int i = 0; i < no2; i++) {
rule.add(sc.nextInt());
}
getResult(arr1,rule);
}
public static void getResult(int[] data,TreeSet<Integer> rule){
int countSum = 0;
int countRuleNo =0;
StringBuilder temp = new StringBuilder();
for (int t : rule){
String ruleNo = String.valueOf(t);
String dataStr = Arrays.toString(data);
StringBuilder sb = new StringBuilder();
if(dataStr.contains(ruleNo)){
countRuleNo++;
int rNo = 0;
for (int i = 0; i < data.length; i++) {
String no = String.valueOf(data[i]);
if(no.contains(ruleNo)){
rNo++;
countSum++;
sb.append(i).append(" ").append(data[i]).append(" ");
}
}
temp.append(ruleNo).append(" ").append(rNo).append(" ").append(sb.toString());
}
}
countSum = countSum*2 + countRuleNo*2;
StringBuilder result = new StringBuilder();
result.append(countSum).append(" ").append(temp.substring(0,temp.toString().length()-1));
System.out.println(result.toString());
}}
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] I = new int[n];
for (int i = 0; i < I.length; i++) {
I[i] = scanner.nextInt();
}
int m = scanner.nextInt();
int[] R = new int[m];
for (int i = 0; i < R.length; i++) {
R[i] = scanner.nextInt();
}
solution(I, R);
}
private static void solution(int[] I, int[] R) {
//去重排序
int[] array = IntStream.of(R).distinct().toArray();
Arrays.sort(array);
//输出的总数字
int all = 0;
StringBuilder builder = new StringBuilder();
for (int j : array) {
int count = 0;
StringBuilder stringBuilder = new StringBuilder();
for (int index = 0; index < I.length; index++) {
if (String.valueOf(I[index]).contains(String.valueOf(j))) {
stringBuilder
.append(index)//索引和值
.append(" ")
.append(I[index])
.append(" ");
count++;
}
}
if (count == 0) continue;
builder
.append(j)//输出R<i>
.append(" ")
.append(count)//输出满足条件的I的个数
.append(" ")
.append(stringBuilder);
all = all + 2 + count * 2;
}
System.out.println(all + " " + builder.toString().trim());
}
}
import java.util.Scanner;
import java.util.HashMap;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int Inum = in.nextInt(), i = 0, j, count = 0;
int[] result = new int[10000]; // 存储最终输出的结果
int[] I = new int[Inum]; // 存储序列I
for (i = 0; i < Inum; i++) {
I[i] = in.nextInt();
}
int Seqn = in.nextInt();
// 哈希表存储不重复的序列R,及各元素出现次数
HashMap<Integer,Integer> r = new HashMap<Integer,Integer>();
for (i = 0; i < Seqn; i++) {
r.put(in.nextInt(), 0);
}
int[] R = new int[r.size()];
i = 0;
for (Integer k: r.keySet()) {
R[i++] = k;
}
// 给R序列排序,放在R数组中
for (i = 0; i < r.size()-1; i++) {
for (j = i+1; j < r.size(); j++) {
if (R[i] > R[j]) {
count = R[i];
R[i] = R[j];
R[j] = count;
}
}
}
count = 0;
for (j = 0; j < r.size(); j++) {
for (i = 0; i < Inum; i++) {
if ((I[i]+"").contains(R[j]+"")) {
r.put(R[j], r.get(R[j])+1);
result[count++] = i;
result[count++] = I[i];
}
}
}
for (Integer k: r.keySet()) {
if (r.get(k) != 0) {
count += 2; // 需要输出R[j]和个数
}
}
System.out.print(count+" ");
count = 0; // 准备输出
for (i = 0; i < r.size(); i++) {
if (r.get(R[i]) == 0) {
continue;
} else {
System.out.print(R[i]+" "+r.get(R[i])+" ");
for (j = count; j < count+2*r.get(R[i]); j++) {
System.out.print(result[j]+" ");
}
count = j;
}
}
}
}
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 读取I序列
int I_num = in.nextInt();
int[] arr_I = new int[I_num];
for (int i = 0; i < arr_I.length; i++) {
arr_I[i] = in.nextInt();
}
// 读取R序列,TreeSet同时去重和排序
int R_num = in.nextInt();
Set<Integer> set = new TreeSet<>();
for (int i = 0; i < R_num; i++) {
set.add(in.nextInt());
}
int[] arr_R = new int[set.size()];
int flag = 0;
for (Integer i : set.toArray(new Integer[0])) {
arr_R[flag++] = i;
}
// flags 存放每个R<i>在I中符合的数的个数,大于0则说明存在符合的数
int[] flags = new int[arr_R.length];
// 存放匹配的数的索引
int[][] indexs = new int[arr_R.length][arr_I.length];
// 存放匹配的数的数值
int[][] values = new int[arr_R.length][arr_I.length];
for (int i = 0; i < arr_R.length; i++) {
flag = 0;// 重置flag
String part = String.valueOf(arr_R[i]);
for (int j = 0; j < arr_I.length; j++) {
String str = String.valueOf(arr_I[j]);
if (str.contains(part)) {
indexs[i][flag] = j;
values[i][flag] = arr_I[j];
flag++;
}
}
flags[i] = flag;
}
// 统计要输出的数字个数
int count = 0;
for (int i : flags) {
if (i > 0) {
count += 2; // 需要输出 R<i> 以及在 I 中匹配的个数(两个数)
count += i * 2;// 需要输出I中匹配的数的索引及其数值(i*2个数)
}
}
// 输出格式
System.out.print(count);
for (int i = 0; i < arr_R.length; i++) {
if (flags[i] > 0) {
System.out.print(" " + arr_R[i] + " " + flags[i]);
for (int j = 0; j < flags[i]; j++) {
System.out.print(" " + indexs[i][j] + " " + values[i][j]);
}
}
}
}
} import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Map<Integer,List<int[]>> sequence2 = new TreeMap<>();
int[] sequence1 = null;
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
sequence1 = new int[a];
for (int i =0;i<a ;i++){
sequence1[i]=in.nextInt();
}
int b = in.nextInt();
for (int i =0;i<b ;i++){
sequence2.put(in.nextInt(),new ArrayList<>());
}
}
for(int i = 0 ; i< sequence1.length ; i ++){
final String sequence = sequence1[i]+"" ;
final int i1= i ;
sequence2.forEach((key,value) ->{
if(sequence.contains(key + "")){
value.add(new int[]{i1,Integer.parseInt(sequence)});
}
});
};
List<Integer> sq = new ArrayList<>() ;
sequence2.forEach((key,value) ->{
if(value.size() > 0){
sq.add(key);
sq.add(value.size());
value.forEach(s -> {
sq.add(s[0]);
sq.add(s[1]);
});
}
});
System.out.printf(sq.size() +" ");
sq.forEach(ss ->System.out.print(ss +" "));
}
} import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 相同的R<i>只输出索引小的
// R<i>从小到大排序
// 输出格式 总数 R<i> R<i>匹配数 l索引 l值
while (in.hasNextInt()) {
String[] iArr = in.nextLine().split(" "); // 忽视index=0
String[] rArr = in.nextLine().split(" "); // r不需考虑坐标
if(rArr[0].equals("0") || iArr[0].equals("0")){
System.out.println("0");
continue;
}
// r数组转换为Integer
int[] rNums = new int[rArr.length-1];
for(int i=0; i<rNums.length; i++){
rNums[i] = Integer.parseInt(rArr[i+1]);
}
// I包含R用字符串匹配实现
// List<int[]> 存储I中匹配成功的串
Map<Integer,List<int[]>> map = new HashMap<>();
List<Integer> ans = new ArrayList<>(); // 存储答案key值
int count = 0; // 记录输出数据量
for(int i=0; i<rNums.length; i++){
if(!map.containsKey(rNums[i])){
List<int[]> rNumAns = match(iArr,""+rNums[i]); // 匹配
if(!rNumAns.isEmpty()){
ans.add(rNums[i]);
map.put(rNums[i],rNumAns);
count += (rNumAns.size()*2 + 2);
}
}
}
// 输出数据
StringBuffer s = new StringBuffer();
s.append(count);
Collections.sort(ans); // 排序答案Key值
List<int[]> temp = new ArrayList<>();
for(int num:ans){
temp = map.get(num);
s.append(" " + num + " " + temp.size());
for(int[] tempSet:temp)
s.append(" "+tempSet[0]+" "+tempSet[1]); // 依次输出坐标和值
}
System.out.println(s.toString());
}
}
public static List<int[]> match(String[] iArr, String rNum){
List<int[]> rNumAns = new ArrayList<>();
for(int i=1; i<iArr.length; i++){
if(iArr[i].matches("(.*)"+rNum+"(.*)")){
int[] temp = new int[2];
temp[0] = i-1;
temp[1] = Integer.parseInt(iArr[i]);
rNumAns.add(temp);
}
}
return rNumAns;
}
} import java.util.*;
import java.util.stream.Collectors;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
static List<Integer> l = new ArrayList();
static List<Integer> r = new ArrayList();
static List<Integer> ans = new ArrayList();
static class Item {
int dx;
int val;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int n = in.nextInt();
for (int i = 0; i < n; ++ i) l.add(in.nextInt());
n = in.nextInt();
for (int i = 0; i < n; ++ i) r.add(in.nextInt());
r = r.stream().distinct().sorted().collect(Collectors.toList());
for (int a : r) {
List<Item> t = new ArrayList();
for (int i = 0; i < l.size(); ++ i) {
String str = l.get(i) + "";
if (str.contains(a + "")) {
Item it = new Item();
it.dx = i; it.val = l.get(i);
t.add(it);
}
}
if (t.size() > 0) {
ans.add(a);
ans.add(t.size());
for (Item it : t) {
ans.add(it.dx);
ans.add(it.val);
}
}
}
System.out.print(ans.size() + " ");
for (int a : ans) System.out.print(a + " ");
}
}
} 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();
String[] str = in.nextLine().split(" ");
//处理第二行
int m = in.nextInt();
Set<Integer> set = new TreeSet<>();//排序+去重
for (int j = 0; j < m; j++) {
set.add(in.nextInt());
}
//寻找符合各个要求的元素
List<List<String>> list = new ArrayList<>();
for (int i : set) {
List<String> temp = new ArrayList<>();
for (int k = 1; k < n + 1; k++) {
if (str[k].contains(Integer.toString(i))) {
temp.add(Integer.toString(k - 1) + " " + str[k]);
}
}
list.add(temp);
}
//计算待输出的元素个数
int total = 0;
for (int i = 0; i < list.size(); i++) {
int size=list.get(i).size();
total += 2 * size;
if (size != 0) {
total += 2;//如果没有满足条件的就不+2
}
}
//按格式输出元素
List<Integer> nums=new ArrayList<>(set);
System.out.print(total);
for (int i = 0; i < list.size(); i++) {
int size=list.get(i).size();
if (size != 0) {
System.out.print(" "+nums.get(i)+" "+size);
}
for(int j=0;j<size;j++){
System.out.print(" "+list.get(i).get(j));
}
}
}
} import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNext()) { // 注意 while 处理多个 case
//储存R
int rnum = in.nextInt();
ArrayList<String> rarr = new ArrayList<>();
for (int i = 0; i < rnum; i++) {
rarr.add(in.nextInt() + "");
}
//储存I
int inum = in.nextInt();
TreeSet<Integer> treeSet = new TreeSet<>();//去重且排序
for (int i = 0; i < inum; i++) {
treeSet.add(in.nextInt());
}
int count = 0;//记录每个I在R中的次数
String res = "";//记录I出现在R中的索引+R值 形如:0 123 3 453 7 3 9 453456 13 453 14 123
LinkedHashSet<String> linkedHashSet = new LinkedHashSet<>();
int num = 0;//num记录res 中非空格的数量
for (Integer i : treeSet) {
String stringI = i.toString();
for (int j = 0; j < rarr.size(); j++) {
if (rarr.get(j).contains(stringI)) {
count++;
res += "".equals(res) ? j + " " + rarr.get(j) : " " + j + " " + rarr.get(j);
}
}
res = stringI + " " + count + " " + res;//这里拼接上对应的I值与R中出现次数 形如:3 6 0 123 3 453 7 3 9 453456 13 453 14 123
if (count == 0) {
res = "";//count为0时 要重置res
continue;
}
linkedHashSet.add(res);
num += count * 2;
count = 0;
res = "";
}
num = num + linkedHashSet.size() * 2;
String out = "";
for (String s : linkedHashSet) {
out += s+" ";
}
System.out.println(num + " " + out);
}
}
} import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 得到序列I的数量
int iNum;
if (in.hasNextInt()) {
iNum = in.nextInt();
} else {
return;
}
if (iNum <= 0) {
return;
}
// 得到序列I的内容
Map<Integer, Integer> iMap = new HashMap<>();
for (int i = 0; i < iNum; i++) {
if (in.hasNextInt()) {
iMap.put(i, in.nextInt());
} else {
return;
}
}
// 得到序列R的数量
int rNum;
if (in.hasNextInt()) {
rNum = in.nextInt();
} else {
return;
}
if (rNum <= 0) {
return;
}
// 得到序列R的内容
TreeSet<Integer> rSet = new TreeSet<>();
for (int i = 0; i < rNum; i++) {
if (in.hasNextInt()) {
rSet.add(in.nextInt());
} else {
return;
}
}
StringBuilder allSb = new StringBuilder();
// 计算序列I中满足包含R内容的部分
for (Integer r : rSet) {
String rStr = String.valueOf(r);
int count = 0;
StringBuilder rSb = new StringBuilder();
for (Map.Entry<Integer, Integer> entry : iMap.entrySet()) {
if (String.valueOf(entry.getValue()).contains(rStr)) {
count++;
rSb.append(entry.getKey())
.append(" ")
.append(entry.getValue())
.append(" ");
}
}
if (count > 0) {
rSb.insert(0, r + " " + count + " ");
allSb.append(rSb.toString());
}
}
// 计算总数量
String all = allSb.toString();
int count = all.split(" ").length;
// 输出
System.out.println(count + " " + all);
}
}
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
//记录输入
int I_num = in.nextInt();
Integer[] I=new Integer[I_num];
List<Integer> list=new ArrayList<Integer>();
for (int i = 0; i < I_num; i++) {
I[i]=in.nextInt();
}
int R_num = in.nextInt();
Integer[] R=new Integer[R_num];
TreeSet<Integer> treeSet=new TreeSet<>();
for (int i = 0; i < R_num; i++) {
R[i]=in.nextInt();
treeSet.add(R[i]);
}
//记录总输出个数,每一个R对应的I个数
int[] R_I_num=new int[treeSet.size()];
int num=0;
int count=0;
for (Integer integer : treeSet) {
for (int i = 0; i < I_num; i++) {
list.clear();
if(I[i].toString().contains(integer.toString())&&list.contains(I[i])!=true)
{
R_I_num[count]+=1;
num+=2;
list.add(I[i]);
}
}
if(R_I_num[count]!=0)
{
num+=2;
}
count++;
}
//打印
System.out.print(num);
count=0;
for (Integer integer : treeSet) {
if (R_I_num[count]!=0){
System.out.print(" "+integer+" "+R_I_num[count]);
for (int i = 0; i < I_num; i++) {
list.clear();
if(I[i].toString().contains(integer.toString())&&list.contains(I[i])!=true)
{
System.out.print(" "+i+" "+I[i]);
list.add(I[i]);
}
}
}
count++;
}
}
}
} import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
int [] i=new int[a];
for(int k=0;k<a;k++){
i[k]=in.nextInt();
}
int b = in.nextInt();
HashSet<Integer> set=new HashSet();
for(int k=0;k<b;k++){
set.add(in.nextInt());
}
List<Integer> list=new ArrayList(set);
Collections.sort(list);
HashMap<Integer,List<Integer>> map=new HashMap();
for(int k:list){
List<Integer> indexes=new ArrayList();
for(int j=0;j<a;j++){
boolean contain= String.valueOf(i[j]).contains(k+"");
if(contain){
indexes.add(j);
}
}
map.put(k,indexes);
}
List<Integer> result=new ArrayList();
for(int k:list){
List<Integer> data=map.get(k);
if(data.size()>0){
result.add(k);
result.add(data.size());
for(int m=0;m<data.size();m++){
int index=data.get(m);
result.add(index);
result.add(i[index]);
}
}
}
System.out.print(result.size());
for(int n:result){
System.out.print(" "+n);
}
}
}
} import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
// I 15 123 456 786 453 46 7 5 3 665 453456 745 456 786 453 123
// R 5 6 3 6 3 0
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String iLIne = in.nextLine();
String rLIne = in.nextLine();
String[] iArr = iLIne.split(" ");
String[] rArr = rLIne.split(" ");
// 存放 R<i>
Map<Integer, Integer> Ri = new LinkedHashMap<>();
// 存放 R<i> 和 索引 <==> I
Map<Integer, LinkedHashMap<Integer, Integer>> index = new LinkedHashMap<>();
// 存放 R<i> 和 索引的顺序
Map<Integer, List<Integer>> sx = new HashMap<>();
String R = "";
String I = "";
for (int i = 1; i <= Integer.parseInt(rArr[0]); i++) {
R = rArr[i];
for (int j = 1; j <= Integer.parseInt(iArr[0]); j++) {
I = iArr[j];
if (I.contains(R)) {
Integer key = Integer.valueOf(R);
LinkedHashMap<Integer, Integer> map = index.get(key);
if (map == null) {
Ri.put(key, Ri.getOrDefault(key, 0) + 1);
map = new LinkedHashMap<>();
map.put(j - 1, Integer.valueOf(I));
index.put(key, map);
List<Integer> sxList = new ArrayList<>();
sxList.add(j - 1);
sx.put(key, sxList);
} else {
if (map.get(j - 1) == null) {
Ri.put(key, Ri.getOrDefault(key, 0) + 1);
map.put(j - 1, Integer.valueOf(I));
index.put(key, map);
List<Integer> sxList = sx.get(key);
sxList.add(j - 1);
sx.put(key, sxList);
}
}
}
}
}
List<Integer> list = new ArrayList<>();
List<Integer> ketSet = new ArrayList<>(Ri.keySet());
ketSet.sort((a, b) -> a.compareTo(b));
for (Integer key : ketSet) {
list.add(key);
LinkedHashMap<Integer, Integer> map = index.get(key);
List<Integer> sxList = sx.get(key);
list.add(Ri.get(key));
sxList.forEach(index1 -> {
list.add(index1);
list.add(map.get(index1));
});
}
StringBuilder builder = new StringBuilder();
builder.append(list.size());
for (int i=0; i<list.size(); i++) {
builder.append(" ").append(list.get(i));
}
System.out.print(builder.toString());
// 这个会导致格式不对
// String result = list.toString().replace("[", "").replace("]", "").replace(",", " ");
// System.out.print(list.size() + " " + result);
}
}