Cod sursa(job #2611200)

Utilizator EdythestarGhiriti Edmond Edythestar Data 6 mai 2020 16:03:26
Problema Potrivirea sirurilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <iostream>
#include<fstream>
#include<string>
#include <vector>

using namespace std;

int main() {
	string minta, str;
	ifstream fin("strmatch.in");
	ofstream fout("strmatch.out");
	getline(fin, minta);
	getline(fin, str);
	int minta_hossz = minta.size();
	int str_hossz = str.size();
    int db = 0;
    vector<int> a;
    for (int i = 0; i < str_hossz; i++) {
        int j;
        for (j = 0; j < minta_hossz; j++) {
            if (str[i + j] != minta[j]) break;
            if (j == minta_hossz - 1) {
                a.push_back(i);
                db++;
            }
        }
    }
    fout << db << "\n";
    if (db > 1000) {
        for (int i = 0; i <= 999; i++) {
            fout << a[i] << " ";
        }
    }
    else {
        for (auto& e : a) {
            fout << e << " ";
        }
    }
}