#include<bits/stdc++.h>
using namespace std;
#define maxn 1000005
int n;
string s;
int jmin,f[1000],t[1000];
bool kt(int i,int j)
{
for(int k=i;k<=(i+j)/2+1;k++)
{
// cout<<i<<" "<<j<<endl;
if(s[k]!=s[j+i-k]) return false;
}
return true;
}
bool ss(string x,string y)
{
while(x.size()<y.size()) x="0"+x;
while(y.size()<x.size()) y="0"+y;
if(x>y) return true;
else return false;
}
void truy_vet()
{
string r="",res="";//,a[300];
int d=0;
while(f[n]>0)
{
r="";
for(int i=t[n]+1;i<=n;i++) r=r+s[i];
d++;
if(ss(r,res)==true) res=r;
n=t[n];
}
cout<<res.size()<<endl;
cout<<res<<endl;
}
void giai() {
f[0]=0;f[1]=1;
for(int i=2;i<=n;i++)
{
jmin=i-1;
for(int j=0;j<=i-1;j++)
{
if(kt(j+1,i)==true&&f[jmin]>f[j])
{
jmin=j;
}
f[i]=f[jmin]+1;
t[i]=jmin;
}
}
truy_vet();
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
freopen("a.inp", "r", stdin);
freopen("a.out", "w", stdout);
cin>>s;
n=s.length();
s=' '+s;
giai();
}
* Chuyên dạy lập trình ONLINE cho học sinh THCS, THPT *.
Mọi giao lưu, trao đổi, xin liên hệ: Lê Quang Vinh - zalo: 037.803.8755.
Page: Lớp học Code Sky
Group FB1: Ôn thi HSG9 - THTB - TS10 chuyên tin
Group FB2: Học Scratch - Ôn thi Tin học trẻ bảng A
Chủ Nhật, 5 tháng 12, 2021
2021 TS10 DANANG B4. Số đối xứng
Đăng ký:
Đăng Nhận xét (Atom)
Không có nhận xét nào:
Đăng nhận xét
Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.