#include <iostream>
#include <string>
using namespace std;

// Funkcja do wyszukiwania wzorca w tekście metodą naiwną
void naiveSearch(const string& text, const string& pattern) {
    int n = text.length();
    int m = pattern.length();

    for (int i = 0; i <= n - m; i++) {
        int j;
        for (j = 0; j < m; j++) {
            if (text[i + j] != pattern[j]) {
                break; // Przerwij, jeśli znaki się różnią
            }
        }
        if (j == m) {
            cout << "Znaleziono wzorzec na pozycji: " << i << endl;
        }
    }
}

int main() {
    string text, pattern;

    cout << "Podaj tekst: ";
    getline(cin, text);
    cout << "Podaj wzorzec do wyszukania: ";
    getline(cin, pattern);

    naiveSearch(text, pattern);

    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: