#include <iostream>
#include <string>
#include <vector>
using namespace std;
int failure(int n, string P, vector<int> F);
int main()
{
vector<int> ans;
string input;
cin >> input;
int n = input.length();
ans.push_back(0);
for (int i = 1; i < n; i++)
{
ans.push_back(failure(i, input, ans));
}
for (int i = 0; i < n; i++)
{
cout << ans[i] << " ";
}
return 0;
}
int failure(int n, string P, vector<int> F)
{
string tmp;
int half;
int ans = 0;
for (int i = 0; i <= n; i++)
{
tmp.insert(tmp.end(), P[i]);
}
int len = tmp.length();
if (len % 2 == 0)
{
half = len / 2;
}
else
{
half = len / 2 + 1;
}
for (int i = 0; i < half; i++)
{
string prefix;
string suffix;
for (int j = 0; j <= i; j++)
{
prefix.insert(prefix.end(), tmp[j]);
suffix.insert(suffix.begin(), tmp[len - j -1]);
}
if (ans < i + 1 && suffix == prefix)
{
ans = i + 1;
}
}
return ans;
}
'vidigummy KAU > 2020년2학기알고리즘' 카테고리의 다른 글
알고리즘 과제 4 (0) | 2021.01.03 |
---|---|
알고리즘 과제 2 (0) | 2021.01.03 |
알고리즘 기초 과제1 (0) | 2021.01.03 |