Cod sursa(job #1467964)

Utilizator shirazEliot Hugo shiraz Data 5 august 2015 00:56:30
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <tr1/functional>
using namespace std;
int main()
{ifstream f("strmatch.in");
ofstream g("strmatch.out");
    vector<int> a;
    string n,m;
    f>>m;f>>n;
    tr1 ::hash<char> hsh;
    long  q=0,w=0, t=0, x=0, v=m.length(), r=n.length();
    if (v>r) g<<0;
    else{


    for (long  i=0;i<v;i++){
        w=w+hsh(m[i]);
    }
    for (long  i=0;i<v;i++){
        q=q+hsh(n[i]);
    }
for (long i=0;i<=r-v;i++){

        if ((q==w)){
            for (long j=0;j<v;j++){

                if (m[j]==n[i+j]) ++t;
                if (t==v ) { if (x>=1000) x++; else
                    {a.push_back(i);t=0;++x;} }

                if (j==v-1) t=0;
            }
        }
        if (i!=r-v)
        q=q+hsh(n[i+v])-hsh(n[i]);
}
g<<x<<'\n';
for (long i=0;i<x && i<1000;i++){
   g<<a[i]<<' ';
}}
    return 0;
}