Pagini recente » Cod sursa (job #3180717) | Istoria paginii utilizator/blacknesta | Cod sursa (job #223414) | Cod sursa (job #1456514) | Cod sursa (job #941043)
Cod sursa(job #941043)
#include <string>
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <cstdio>
//#define maxim(a,b) (a>b)?a:b
using namespace std;
int process_line(string A) {
int ret = 0;
int period = 0;
int cnd = 0;
int s = A.size();
int pos = 1;
while(pos < s) {
if (A[cnd] == A[pos])
{
if (cnd == 0) {period = pos;}
else if (pos % period == 0) ret = pos;
cnd++;pos++;}
else {if (cnd == 0) pos++;
else if (pos % period == 0) ret = pos; cnd = 0;}
}
return ret;
}
int main()
{
ifstream fin ("prefix.in");
ofstream fout("prefix.out");
int T;
int res;
string line;
fin >> T;
getline(fin, line);
for(int i = 0; i < T; i++) {
getline(fin, line); //cout << line << endl;
fout << process_line(line + ' ') << endl;
}
return 0;
}