Pagini recente » Cod sursa (job #2855983) | Cod sursa (job #1628287) | Cod sursa (job #682321) | Cod sursa (job #2633354) | Cod sursa (job #941068)
Cod sursa(job #941068)
#include <string>
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <cstdio>
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;}
cnd++;pos++;}
else {if (cnd == 0) pos++;
else {if (cnd >= period) ret = pos - (pos % period);}
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;
}