Cod sursa(job #1221011)

Utilizator borcanirobertBorcani Robert borcanirobert Data 19 august 2014 11:00:59
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

ifstream fin("strmatch.in");
ofstream fout("strmatch.out");

const int MAXDIM = 2000005;
const int MAXPOZ = 2000005;
char a[MAXDIM], b[MAXDIM];
int poz[MAXPOZ], npoz;
int n, m;
int ap;

int main()
{
    char *p;

    fin.getline( a, MAXDIM ); n = strlen( a );
    fin.getline( b, MAXDIM ); m = strlen( b );

  //  cout << a << '\n' << b; cin.get();

    p = strstr( b, a );

    while ( p )
    {
        ap++;

        poz[++npoz] = p - b;
      //  cout << p - b << '\n'; cin.get();

        p++; p = strstr( p, a );
    }

    fout << ap << '\n';
    for ( int i = 1; i <= npoz; i++ )
        fout << poz[i] << ' ';

    fin.close();
    fout.close();
    return 0;
}