Cod sursa(job #637664)

Utilizator ProtomanAndrei Purice Protoman Data 20 noiembrie 2011 15:51:15
Problema PScPld Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#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 += " ";
	
	int maxGs = -1, mij = 0, sol = 0;
	for (int i = 0; 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], y = i + lung[loc];

		for (; x >= 0 && y < str.size(); lung[loc]++, x--, y++)
			if (str[x] != str[y])
				break;
		
		if (isalnum(str[i]))
			sol += lung[loc] / 2;
		else sol += lung[loc] / 2;

		if (maxGs < y - 1)
			maxGs = y - 1, mij = i;
	}

	cout << sol;

	return 0;
}