Cod sursa(job #941043)

Utilizator andreiagAndrei Galusca andreiag Data 17 aprilie 2013 20:22:12
Problema Prefix Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#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;
}