Pagini recente » Cod sursa (job #2659712) | Cod sursa (job #804394) | Cod sursa (job #1636957) | Cod sursa (job #3041996) | Cod sursa (job #2979282)
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <fstream>
using namespace std;
ifstream cin("pscpld.in");
ofstream cout("pscpld.out");
int rz[2001],n,r,l;
char s[1001],q[2001];
int main()
{
cin>>s;
q[n++]='#';
for(int i=0;s[i]!='\0';i++)
{
q[n++]=s[i];
q[n++]='#';
}
q[n]='\0';
for(int i=0;i<n;i++)
{
if(i>r)
rz[i]=0;
else
rz[i]=min(r-i,rz[r+l-i]);
while(i-rz[i]>=0 && q[i+rz[i]]==q[i-rz[i]])
rz[i]++;
rz[i]--;
if(i+rz[i]>r)
{
r=i+rz[i];
l=i-rz[i];
}
}
int nr=0;
for(int i=0;i<n;i++)
nr=nr+(rz[i]+1)/2;
cout<<nr;
return 0;
}