QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370589 | #552. 字符串匹配问题 | lzy2023 | 0 | 1ms | 3536kb | C++17 | 975b | 2024-03-29 12:42:05 | 2024-03-29 12:42:05 |
answer
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define int ll
const int N = 2e5 + 10, mod = 1e9 + 7;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s, p;
cin >> p >> s;
int n = p.size();
p = p + '#' + s;
// cout<<p<<endl;
vector<int> ne(p.size() + 1);
for (int i = 1; i < n; i++) {
int j = ne[i - 1];
while (j && p[i] != p[j]) j = ne[j - 1];
if (p[i] == p[j]) j++;
ne[i] = j;
}
for (int i = n + 1; i < p.size(); i++) {
int j = ne[i - 1];
while (j && p[i] != p[j] && p[i] != '*' && p[j] != '*') j = ne[j - 1];
cout <<p[i]<<' '<< p[j]<<endl;
if ((p[i] == p[j] || p[i] == '*' || p[j] == '*') && p[i] != '#' && p[j] != '#') j++;
ne[i] = j;
// cout<<i<<' '<<ne[i-1]<<'|'<<endl;
if(ne[i] == n) cout << i - 2 - n << ' ';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3536kb
input:
cabacacccbacccaabacacaabcabbabcaccbcabbacbcb aaaccabacaaabb*abaaaa*bcabacacccba*ccaabacadaabcabba*kac*b*abbacabacacccbacccaa*acacaabcabbabca***cabbacbcbcabbacbcbbccbcacbaccbacaacc***bbbabccc**bbcbaaaaaabaabaacbc*cbcca*ccbabbacb*caaabcaba*acccbacccaabcabadac*cbacccaabacacaabca**abcucc*cxbbacb*bbacacc...
output:
a c a c a c c c c c a a b b a a c c a a a c a c b c b c * c a a b b a a a c a c a c * c b c c c a a b b a a c c a a c c c c c c b b a a * c c c c c a a a a b b a a c c a a d c a c a c b c c c a a b b b c a c * c k c a c c c * a b b * a a c b c b c a c c c a a b b a a c c a a c c c c c c b b a a c c ...
result:
wrong output format Expected integer, but "a" found
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%