MeehoweCK

Untitled

Nov 27th, 2018
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*
  6. A15. Napisać funkcję
  7. bool g(char* s, int n)
  8. która zwraca true wtedy i tylko wtedy, gdy napis s zawiera ciąg co najmniej n
  9. kolejnych jednakowych znaków.
  10. */
  11.  
  12. bool g(char* s, int n)
  13. {
  14.     bool flaga;
  15.     for(int i = 0; i < 1000; ++i)
  16.     {
  17.         if(!s[i]) break;
  18.         flaga = true;
  19.         for(int j = 1; j < n; ++j)
  20.             if(s[i] != s[i+j])
  21.             {
  22.                 flaga = false;
  23.                 break;
  24.             }
  25.         if(flaga)
  26.             return true;
  27.     }
  28.     return false;
  29. }
  30.  
  31. int main()
  32. {
  33.     char napis[1000] = "aaabbbbcc";
  34.     cout << g(napis, 5);
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment