vertc

14-11

Nov 14th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main () {
  7.     string tekst, wzorzec;
  8.     cout<<"Podaj tekst: "<<endl;
  9.     getline(cin, tekst);
  10.     int tekst_dl = tekst.size();
  11.     cout<<"Podaj wzorzec"<<endl;
  12.     getline(cin, wzorzec);
  13.     int wzorzec_dl = wzorzec.size();
  14.     int spr = 0;
  15.     for (int i=0;i<=tekst_dl - wzorzec_dl;i++) {
  16.         spr = 1;
  17.         for(int j=0; j<wzorzec_dl; j++)
  18.         if(tekst[j+i]!=wzorzec[j]) {
  19.             spr = 0;
  20.             break;
  21.         }
  22.         if(spr == 1) {
  23.             cout<<"Wzorzec znaleziono na "<<i+1<<" pozycji"<<endl;
  24.             break;
  25.         }
  26.     }
  27.     if(spr == 0) cout<<"Wzorca nie odnaleziono";
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment