Cod sursa(job #1467863)

Utilizator shirazEliot Hugo shiraz Data 4 august 2015 22:15:31
Problema Potrivirea sirurilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <tr1/functional>
using namespace std;
int main()
{
    vector<int> a;
    string n,m;
    getline(cin,m);getline(cin,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 (long 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]);
}
cout<<x<<'\n';
for (long i=0;i<x;i++){
   cout<<a[i]<<' ';
}
    return 0;
}