Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. {
  2. class Program
  3. {
  4. static bool czyIstnieje(string tekst, string wyraz, int licznik)
  5. {
  6. int licznik1 = 0;
  7. bool flag = false;
  8. for (int i = 0; i < tekst.Length; i++)
  9. {
  10. if (tekst[i] == wyraz[0])
  11. {
  12. flag = true;
  13. for (int j = 0; j < wyraz.Length; j++)
  14. {
  15. if (i + j >= tekst.Length)
  16. {
  17. return false;
  18. }
  19. if (tekst[i + j] != wyraz[j])
  20. {
  21. flag = false;
  22. break;
  23. }
  24. }
  25.  
  26. if (flag)
  27. {
  28.  
  29. licznik1 = licznik1 + 1;
  30. if (licznik1 == licznik)
  31. {
  32. return true;
  33. }
  34.  
  35.  
  36.  
  37. }
  38.  
  39. }
  40.  
  41.  
  42.  
  43. }
  44.  
  45. return false;
  46. }
  47. static void Main(string[] args)
  48. {
  49. Console.WriteLine(czyIstnieje("Ala ma ma Ala kota", "ma", 1 ));
  50. Console.ReadKey();
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement