Cod sursa(job #2677251)

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

using namespace std;

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

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;
            if(cnt < 1000){
                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;
}