Cod sursa(job #2861633)

Utilizator FasoleboiTudor Gadalean Fasoleboi Data 4 martie 2022 10:29:35
Problema Potrivirea sirurilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.88 kb
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;

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

string a, b, c = "";
vector <int> pos;
int cnt, ind;

int main(){
    fin>>a>>b;
    int n = b.size(), m = a.size();
    for(int i=0;i<n;i++){
        c+=b[i];
        if(i+1>=m){
            if(c==a){
                cnt++;
                pos.push_back(i-m+1);
            }
            c = c.substr(1);
        }
    }
    /*if(a.size()>b.size()){
        cout<<0;
    }else{
        for(int i=0;i<b.size()-a.size()+1;i++){
            string c = b.substr(i, a.size());
            if(c==a){
                cnt++;
                pos.push_back(i);
            }
        }
        */
    fout<<cnt<<'\n';
    for(auto it: pos){
        fout<<it<<" ";
        ind++;
        if(ind==1000) break;
    }
    return 0;
}