Cod sursa(job #2240632)

Utilizator AnimusFabian Animus Data 13 septembrie 2018 20:06:35
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int c = 0;
int ans[1000000];
int r = 0;

void strmatch(string pat, string txt){
    int m = pat.length();
    int n = txt.length();

    for(int i = 0; i<=n-m;i++){
        int j;

        for(j = 0; j<m;++j){
            if(txt[i+j] != pat[j]){
                break;
            }
        }
        if(j == m){
            ans[r] = i;
            ++r;
            ++c;
        }
    }
}

int main()
{
    ifstream in("strmatch.in");
    ofstream out("strmatch.out");

    string a, b;

    in >> a >> b;

    strmatch(a, b);

    out << c << endl;

    for(int i = 0; i < c;++i){
        out << ans[i] << " ";
    }
}