Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main () {
- string tekst, wzorzec;
- cout<<"Podaj tekst: "<<endl;
- getline(cin, tekst);
- int tekst_dl = tekst.size();
- cout<<"Podaj wzorzec"<<endl;
- getline(cin, wzorzec);
- int wzorzec_dl = wzorzec.size();
- int spr = 0;
- for (int i=0;i<=tekst_dl - wzorzec_dl;i++) {
- spr = 1;
- for(int j=0; j<wzorzec_dl; j++)
- if(tekst[j+i]!=wzorzec[j]) {
- spr = 0;
- break;
- }
- if(spr == 1) {
- cout<<"Wzorzec znaleziono na "<<i+1<<" pozycji"<<endl;
- break;
- }
- }
- if(spr == 0) cout<<"Wzorca nie odnaleziono";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment