Topic Portal
Test instructions: South of Training (P216)
Analysis: To find the most occurrences of the string, then each string map id,cnt record the maximum number of times can be.
#include <bits/stdc++.h>using namespace Std;const int N = + 5;const int NODE = N * 70;const int LEN = 1e6 + 5;co NST int SIZE = 26;struct AC {int ch[node][size], Fail[node], Val[node], cnt[n], sz; Map<string, int> MS; void Clear (void) {memset (ch[0], 0, sizeof (ch[0])); memset (CNT, 0, sizeof (CNT)); SZ = 1; Val[0] = 0; Ms.clear (); } int idx (char c) {return C-' a '; } void Insert (char *p, int id) {ms[string (P)] = ID; int u = 0; for (int c, i=0; P[i]; ++i) {c = idx (P[i]); if (!ch[u][c]) {memset (Ch[sz], 0, sizeof (Ch[sz])); Val[sz] = 0; CH[U][C] = sz++; } u = Ch[u][c]; } Val[u] = ID; } void Build (void) {queue<int> que; fail[0] =-1; int u; for (int i=0; i<size; ++i) {u = ch[0][i]; if (u) {fail[u] = 0; QuE.push (U); }} while (!que.empty ()) {u = Que.front (); Que.pop (); for (int i=0; i<size; ++i) {int &v = ch[u][i]; if (!v) {v = ch[fail[u]][i]; continue; } que.push (v); FAIL[V] = Ch[fail[u]][i]; }}} void query (char *t) {int u = 0, V; for (int c, i=0; T[i]; ++i) {c = idx (T[i]); U = ch[u][c]; v = u; cnt[val[v]]++; }}}ac;char pattern[n][75], text[len];int n;void solve (void) {int best =-1; for (int i=1, i<=n; ++i) {if (Ac.cnt[i] > Best) best = ac.cnt[i]; } printf ("%d\n", best); for (int i=1; i<=n; ++i) {if (ac.cnt[ac.ms[string (pattern[i])] = = Best) {printf ("%s\n", Patt Ern[i]); }}}int Main (void) {while (scanf ("%d", &n) = = 1) {if (!n) break; Ac.clear (); for (int i=1; i<=n; ++i) {scanf ("%s", &pattern[i]); Ac.insert (Pattern[i], i); } ac.build (); scanf ("%s", &text); Ac.query (text); Solve (); } return 0;}
AC automaton LA 4670 dominating Patterns