f416. 果然我的期中程設考搞錯了什麼 - 高中生程式解題系統

本文最後更新於:2024年1月12日 下午

Zerojudge
解題紀錄

f416. 果然我的期中程設考搞錯了什麼 - 高中生程式解題系統

Zerojudge-f416-4.cpp

// Author : ysh
// 2023/11/05 Sun 18:08:50
#include<bits/stdc++.h>
using namespace std;
vector<int> check(string a) {
    vector<int>f(a.size());
    for(int i = 1,len = a.size();i<len;i++) {
        int p = f[i - 1];
        while(a[p] != a[i] && p != 0) p = f[p - 1];
        if(a[p] == a[i]) f[i] = p + 1;
    }
    return f;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;cin>>n;
    string a,b;cin>>a>>b;
    int tmp = a.size(),ans = 0;
    for(int i : check(a + " " + b)) if(i == tmp) ans++;
    cout<<(ans == n ? "YES" : "NO");
    return 0;
}
CPP

f416. 果然我的期中程設考搞錯了什麼 - 高中生程式解題系統
http://mysh212.github.io/algosolution/Zerojudge-f416-4.cpp/
作者
ysh
發布於
2023年11月5日
更新於
2024年1月12日
許可協議