SHARE
TWEET

18. Substring

VanessaShopping Oct 10th, 2016 183 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top