Cod sursa(job #2677243)

Utilizator walentines44Serban Valentin walentines44 Data 26 noiembrie 2020 08:39:00
Problema Potrivirea sirurilor Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include <iostream>
#include <string.h>
#include <fstream>

using namespace std;

#define min(a, b) (a < b?b: a)

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

char string_array[2000005], pattern[2000005];

int main(){
    char *value;
    int vec[1001];
    int n, cnt = 0, OK;
    fin >> pattern;
    fin >> string_array;
    n = strlen(string_array);
    int new_value = 0;
    while(new_value < n){
        value = strstr(string_array + new_value, pattern);
        OK = 0;
        if(value){
            new_value = value - string_array;
            vec[cnt] = new_value;
            cnt++;
            new_value += 1;
            OK = 1;
        }
        if(OK == 0){
            break;
        }

    }
    fout << cnt << "\n";
    for(int i = 0; i < min(cnt, 1000); i++){
        fout << vec[i] << " ";
    }

    return 0;
}