DJColdBrain

Untitled

Jun 7th, 2017
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. using System;
  2.  
  3. public class Substring_broken
  4. {
  5. public static void Main()
  6. {
  7. string text = Console.ReadLine();
  8. int jump = int.Parse(Console.ReadLine());
  9.  
  10. const char Search = 'p';
  11. bool hasMatch = false;
  12.  
  13. for (int i = 0; i < text.Length; i++)
  14. {
  15. if (text[i] == Search)
  16. {
  17. hasMatch = true;
  18.  
  19. int endIndex = jump +1 ;
  20.  
  21. if (endIndex + i> text.Length)
  22. {
  23. endIndex = text.Length - i;
  24. }
  25.  
  26. string matchedString = text.Substring(i, endIndex);
  27. Console.WriteLine(matchedString);
  28. i += jump;
  29. }
  30. }
  31.  
  32. if (!hasMatch)
  33. {
  34. Console.WriteLine("no");
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment