Cod sursa(job #1047847)

Utilizator Aleks10FMI - Petrache Alex Aleks10 Data 4 decembrie 2013 22:20:32
Problema Substr Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <iostream>
#include <fstream>
#include <unordered_map>

using namespace std;

unordered_map<string,int> unmap;
char a[17000];
string substr;
int main()
{
    int n,k,i,j;
    ifstream f("substr.in");
    ofstream g("substr.out");
    f>>n>>k;
    for(i=0;i<n;i++)
        f>>a[i];

    /*substr+='c';
    substr+='d';
    substr.clear();
    substr+='c';*/
    cout<<substr;
    bool ok=true;
    int imp=n-1;
    int maxim=-1;
    while(ok || imp<0){
        maxim=-1;
        for(i=0;i<n-imp;i++){
            substr.clear();
            for(j=i;j<i+imp+1;j++){
                substr+=a[j];
            }
            unmap[substr]++;
            if(unmap[substr]>maxim)
                maxim=unmap[substr];
            //cout<<imp<<" cu "<<unmap[substr]<<" "<<substr;
            //cout<<'\n';
        }
        //cout<<maxim;
        if(maxim>=k){
            g<<imp+1;
            ok=false;
        }
        imp--;
    }
    return 0;
}