Cod sursa(job #2457991)

Utilizator theo2003Theodor Negrescu theo2003 Data 19 septembrie 2019 11:28:11
Problema Potrivirea sirurilor Scor 14
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <fstream>
#include <vector>
using namespace std;
string a, b;
ifstream cin("strmatch.in");
ofstream cout("strmatch.out");
long long int sub = 0;
int pos[1000], p = 0;
int main(){
    cin>>a>>b;
    if(a.size() == 1){
        for(int x = 0;x<b.size();x++){
            if(b[x] == a[0]){
                sub++;
                if(p < 1000)
                    pos[p++] = x + 1;
            }
        }
    }else
    for(int x = 0, y = 0, l = b.size(), sz = a.size();x<l;x++){
        if(b[x] == a[y]){
            y++;
            if(y == sz){
                sub++;
                if(p < 1000)
                    pos[p++] = x - sz + 2;
            }else continue;
        }
        if(b[x] == a[0]){
            y = 1;
        }else y = 0;
    }
    cout<<sub<<'\n';
    for(int x  = 0;x<p;x++){
        cout<<pos[x]<<' ';
    }
    return 0;
}