Advertisement
VanessaShopping

18. Substring

Oct 10th, 2016
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 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.         bool hasMatch = false;
  11.  
  12.         for (int i = 0; i < text.Length; i++)
  13.         {
  14.             if (text[i] == 'p')
  15.             {
  16.                 hasMatch = true;
  17.  
  18.                 int endIndex = jump + 1;
  19.  
  20.                 if (endIndex + i > text.Length)
  21.                 {
  22.                     endIndex = text.Length - i;
  23.                 }
  24.  
  25.                 string matchedString = text.Substring(i, endIndex);
  26.                 Console.WriteLine(matchedString);
  27.                 i += endIndex;
  28.             }
  29.         }
  30.  
  31.         if (!hasMatch)
  32.         {
  33.             Console.WriteLine("no");
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement