Pagini recente » Cod sursa (job #1941325) | Cod sursa (job #1337570) | Cod sursa (job #2741643) | Cod sursa (job #1312543) | Cod sursa (job #637572)
Cod sursa(job #637572)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int lung[2000010];
int main()
{
ifstream cin("pscpld.in");
ofstream cout("pscpld.out");
string strCit, str;
cin >> strCit;
for (int i = 0; i < strCit.size(); i++)
{
str += " ";
str += strCit[i];
}
str[0] = 'X';
int maxGs = 0, mij = 0, sol = 0;
for (int i = 1; i < str.size(); i++)
{
int x, y, loc = i;
if (maxGs < i)
maxGs = i, mij = i, lung[loc] = 1;
lung[loc] = lung[mij - (loc - mij)];
x = i - (lung[loc] + 1) / 2 - 1, y = i + (lung[loc] + 1) / 2 + 1;
for (; x > 0 && y < str.size(); lung[loc]++, x--, y++)
if (str[x] != str[y])
break;
if (isalnum(str[i]))
sol += (lung[loc] + 1) / 2;
else sol += lung[loc] / 2;
if (maxGs < y - 1)
maxGs = y - 1, mij = i;
}
cout << sol;
return 0;
}