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

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

Zerojudge
解題紀錄

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

Zerojudge-f416-3.cpp

// Author : ysh
// 06/22/2022 Wed 18:08:26.56
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include<C:\Users\Public\debug.h>
#else
#define debug(...) '*'
#define printf(...) '*'
#endif

vector<int> check(string a) {
    vector<int>f(a.size());
    for(int i = 1,len = a.size();i<len;i++) {
        int j = f.at(i - 1);
        while(j > 0 && a.at(i) != a.at(j)) j = f.at(j - 1);
        if(a.at(j) == a.at(i)) f.at(i) = j + 1;
    }
    return f;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;cin>>n;
    string a,b;cin>>a>>b;
    string c = a + ' ' + b;
    vector<int>f(check(c));
    debug(f);
    int r = a.size();
    int ans = 0;
    for(int i : f) {
        if(i == r) ans++;
    }
    cout<<(ans == n ? "YES" : "NO")<<"\n";
    return 0;
}

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