涨知识了,还有这种字符串匹配方式。
用bitset() 数据结构,来记录每个合法字符出现的位置, 然后去匹配。
#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
bitset<1010> a[20];
bitset<1010> ans;
const int Max_N = 1e6+20;
int n, x, y;
char str[5*Max_N];
int main()
{
int T;
while(scanf("%d", &T) != EOF) {
for (int i = 0; i <= 10; i++)
a[i].reset();
ans.reset();
for (int i = 1; i <= T; i++) {
scanf("%d", &x);
for (int j = 1; j <= x; j++) {
scanf("%d", &y);
a[y].set(i-1);
}
}
/*getchar();
gets(str);*/
scanf("%s", str);
int len = strlen(str);
//cout << len << endl;
for (int i = 0; i < len; i++) {
ans = ans << 1;
ans[0] = 1;
ans &= a[str[i] - '0'];
if (ans[T-1] == 1) {
char temp = str[i+1];
str[i+1] = '\0';
puts(str+i-T+1);
str[i+1] = temp;
}
//cout << i << endl;
}
}
return 0;
}