Cod sursa(job #941068)

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