#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
struct Trie {
int fail;
int son[26];
int end;
} AC[1000005];
struct Str {
int num, pos;
} str[1000005];
bool cmp(Str a, Str b) {
if(a.num != b.num) return a.num > b.num;
else return a.pos < b.pos;
}
int cnt = 0;
void Clean(int x) {
AC[x].fail = AC[x].end = 0;
memset(AC[x].son, 0, sizeof(AC[x].son));
}
inline void Build(string s, int num) {
int l = s.length();
int now = 0;
for(int i = 0; i < l; i++) {
if(AC[now].son[s[i] - 'a'] == 0) {
AC[now].son[s[i] - 'a'] = ++cnt;
Clean(cnt);
}
now = AC[now].son[s[i] - 'a'];
}
AC[now].end = num;
}
void getFail() {
queue<int> q;
for(int i = 0; i < 26; i++) {
if(AC[0].son[i] != 0) {
AC[AC[0].son[i]].fail = 0;
q.push(AC[0].son[i]);
}
}
while(!q.empty()) {
int u = q.front();
q.pop();
for(int i = 0; i < 26; i++) {
if(AC[u].son[i] != 0) {
AC[AC[u].son[i]].fail = AC[AC[u].fail].son[i];
q.push(AC[u].son[i]);
} else {
AC[u].son[i] = AC[AC[u].fail].son[i];
}
}
}
}
void AC_Query(string s) {
int l = s.length();
int now = 0;
for(int i = 0; i < l; i++) {
now = AC[now].son[s[i] - 'a'];
for(int t = now; t; t = AC[t].fail) {
str[AC[t].end].num++;
}
}
}
int main() {
freopen("data.txt", "r", stdin);
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
while(cin >> n && n) {
cnt = 0;
Clean(0);
vector<string> v;
v.push_back(" ");
for(int i = 1; i <= n; i++) {
string s;
cin >> s;
str[i].pos = i;
str[i].num = 0;
Build(s, i);
v.push_back(s);
}
AC[0].fail = 0;
getFail();
string t;
cin >> t;
AC_Query(t);
sort(str + 1, str + n + 1, cmp);
int times = str[1].num;
cout << times << endl;
for(int i = 1; i <= n; i++) {
if(str[i].num == times) {
cout << v[str[i].pos] << endl;
} else {
break;
}
}
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2020-03-06 蓝桥杯省赛 区间移位(二分+玄学贪心)