题目描述:
输入描述:
一组输入整数序列I和一组规则整数序列R,I和R序列的第一个整数为序列的个数(个数不包含第一个整数);整数范围为0~0xFFFFFFFF,序列个数不限
输出描述:
从R依次中取出R<i>,对I进行处理,找到满足条件的I<j>:
I<j>整数对应的数字需要连续包含R<i>对应的数字。比如R<i>为23,I<j>为231,那么I<j>包含了R<i>,条件满足 。
按R<i>从小到大的顺序:
(1)先输出R<i>;
(2)再输出满足条件的I<j>的个数;
(3)然后输出满足条件的I<j>在I序列中的位置索引(从0开始);
(4)最后再输出I<j>。
附加条件:
(1)R<i>需要从小到大排序。相同的R<i>只需要输出索引小的以及满足条件的I<j>,索引大的需要过滤掉
(2)如果没有满足条件的I<j>,对应的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<j>,不输出0,而下一个R<i>是3
6--- 存在6个包含3的I<j>
0--- 123所在的原序号为0
123--- 123包含3,满足条件
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext())
{
int totalI = scanner.nextInt();
int[] arrI = new int[totalI];
for (int i = 0; i < totalI; i++)
arrI[i] = scanner.nextInt();
int totalR = scanner.nextInt();
int[] arrR = new int[totalR];
for (int i = 0; i < totalR; i++)
arrR[i] = scanner.nextInt();
Arrays.sort(arrR);
Set<Integer> listR = new LinkedHashSet<>();
for (int i = 0; i < totalR; i++)
if (!listR.contains(arrR[i]))
listR.add(arrR[i]);
ArrayList<Integer> listRes = new ArrayList<>();
for (int valueR: listR)
{
Map<Integer, Integer> map = new LinkedHashMap<>();
for (int i = 0; i < totalI; i++)
{
if (String.valueOf(arrI[i]).contains(String.valueOf(valueR)))
map.put(i, arrI[i]);
}
if (map.size() != 0) {
listRes.add(valueR);
listRes.add(map.size());
for (int index : map.keySet()) {
listRes.add(index);
listRes.add(map.get(index));
}
}
}
System.out.print(listRes.size());
for (int num: listRes)
System.out.print(" " + num);
System.out.println();
}
}
}
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext())
{
String I = scanner.nextLine();
String R = scanner.nextLine();
String[] arrI = I.split(" ");
String[] arrR = R.split(" ");
LinkedList<Integer> res = new LinkedList<>();
Set<Integer> setR = new TreeSet<>();
for (int i = 1; i < arrR.length; i++)
setR.add(Integer.parseInt(arrR[i]));
for (int valueR: setR) {
LinkedList<Integer> tmp = new LinkedList<>();
for (int i = 1; i < arrI.length; i++)
{
if (arrI[i].contains("" + valueR))
{
tmp.add(i - 1);
tmp.add(Integer.parseInt(arrI[i]));
}
}
if (!tmp.isEmpty())
{
res.add(valueR);
res.add(tmp.size() / 2);
res.addAll(tmp);
}
}
System.out.print(res.size());
for (int element: res)
System.out.print(" " + element);
System.out.println();
}
}
}