Advertisement
Guest User

Całe

a guest
Mar 26th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void Find(string tekst,string wzor)
  6. {
  7.     int a=0;
  8.     for(int i=0;i<=tekst.length();i++)
  9.     {
  10.         if(tekst[i]==' ') continue; // Bez tego tez zadziala pomija odstepy
  11.         for(int j=0;j<=wzor.length();j++)
  12.         {
  13.             if(wzor[j]!=tekst[i+j]&&(wzor[j]!='*'||tekst[i+j]==' ')) break;
  14.             if((j+1)==wzor.length()) a++;
  15.         }
  16.  
  17.     }
  18.     if(a>0)
  19.     {
  20.         cout<<"Znaleziono "<<a<<" razy\n";
  21.     }
  22.     else
  23.     {
  24.         cout<<"Nie znaleziono\n";
  25.     }
  26.  
  27. }
  28.  
  29.  
  30. int main()
  31. {
  32.     string tekst = "321 331 341 351 361 371";
  33.     string wzor = "3*1";
  34.     Find(tekst,wzor);
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement