Cod sursa(job #3212198)

Utilizator AlexMoto2006Motoasca Alexandru-Lucian AlexMoto2006 Data 11 martie 2024 12:21:30
Problema Potrivirea sirurilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
// ConsoleApplication2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <fstream>
#include <vector>
#include <string>

using namespace std;

ifstream cin("strmatch.in");
ofstream cout("strmatch.out");

string A, B;
int lenA, lenB;
vector <int> app;

int main() {
    cin >> A >> B;
    lenA = A.size();
    lenB = B.size();
    if (lenA > lenB)
    {
		cout << 0;
		return 0;
	}
    for (int i = 0; i <= lenB - lenA; i++)
    {
        int ok = 1;
        for (int j = i; j < i + lenA; j++)
        {
            if (B[j] != A[j - i])
            {
                ok = 0;
                break;
            }
        }
        if(ok==1)
            app.push_back(i);
    }
    cout << app.size() << "\n";
    for(int i=0;i<app.size();i++)
		cout << app[i] << " ";
    return 0;
}