#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
bool contains(int num, int target) {
string numStr = to_string(num);
string targetStr = to_string(target);
return numStr.find(targetStr) != string::npos;
}
int main() {
int n, m;
while (cin >> n) {
vector<int> I(n);
for (int i = 0; i < n; i++) {
cin >> I[i];
}
cin >> m;
vector<int> R(m);
for (int i = 0; i < m; i++) {
cin >> R[i];
}
// 对R进行排序和去重
set<int> uniqueR(R.begin(), R.end());
vector<int> sortedR(uniqueR.begin(), uniqueR.end());
vector<int> result;
// 处理每个规则数字
for (int r : sortedR) {
vector<pair<int, int>> matches; // (位置, 值)
for (int i = 0; i < n; i++) {
if (contains(I[i], r)) {
matches.push_back({i, I[i]});
}
}
if (!matches.empty()) {
result.push_back(r);
result.push_back(matches.size());
for (auto& match : matches) {
result.push_back(match.first);
result.push_back(match.second);
}
}
}
// 输出结果
cout << result.size() << " ";
for (int i = 0; i < result.size(); i++) {
cout << result[i];
if (i < result.size() - 1) cout << " ";
}
cout << endl;
}
return 0;
}
import java.util.*;
public class Main {
private static boolean contains(int num, int target) {
return String.valueOf(num).contains(String.valueOf(target));
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
int[] I = new int[n];
for (int i = 0; i < n; i++) {
I[i] = sc.nextInt();
}
int m = sc.nextInt();
int[] R = new int[m];
for (int i = 0; i < m; i++) {
R[i] = sc.nextInt();
}
// 对R进行排序和去重
TreeSet<Integer> uniqueR = new TreeSet<>();
for (int r : R) uniqueR.add(r);
List<Integer> result = new ArrayList<>();
// 处理每个规则数字
for (int r : uniqueR) {
List<int[]> matches = new ArrayList<>(); // [位置, 值]
for (int i = 0; i < n; i++) {
if (contains(I[i], r)) {
matches.add(new int[]{i, I[i]});
}
}
if (!matches.isEmpty()) {
result.add(r);
result.add(matches.size());
for (int[] match : matches) {
result.add(match[0]);
result.add(match[1]);
}
}
}
// 输出结果
System.out.print(result.size());
for (int val : result) {
System.out.print(" " + val);
}
System.out.println();
}
}
}
def contains(num, target):
"""检查数字num是否包含target作为子串"""
num_str = str(num)
target_str = str(target)
return target_str in num_str
while True:
try:
# 读取序列I
I = list(map(int, input().split()))
n = I[0]
I = I[1:]
# 读取序列R
R = list(map(int, input().split()))
m = R[0]
R = R[1:]
# 对R进行排序和去重
unique_R = sorted(set(R))
result = []
# 处理每个规则数字
for r in unique_R:
matches = [] # [(位置, 值)]
for i in range(len(I)):
if contains(I[i], r):
matches.append((i, I[i]))
if matches:
result.append(r)
result.append(len(matches))
for pos, val in matches:
result.append(pos)
result.append(val)
# 输出结果
print(len(result), end='')
for i in range(len(result)):
print(f" {result[i]}", end='')
print()
except EOFError:
break