Cod sursa(job #1467856)

Utilizator shirazEliot Hugo shiraz Data 4 august 2015 22:03:35
Problema Potrivirea sirurilor Scor 16
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 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;
    getline(f,m);getline(f,n);
    tr1 ::hash<char> hsh;
    long  q=0,w=0, t=0, x=0, v=m.length(), r=n.length();
    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 (int j=0;j<v;j++){

                if (m[j]==n[i+j]) ++t;
                if (t==v) {a.push_back(i);t=0;++x;}
            }
        }
        q=q+hsh(n[i+v])-hsh(n[i]);
}
g<<x<<'\n';
for (long i=0;i<x;i++){
   g<<a[i]<<' ';
}
    return 0;
}