SHARE
TWEET

Substring

a guest Oct 7th, 2016 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. public class Substring
  4. {
  5.     public static void Main()
  6.     {
  7.         string text = Console.ReadLine();
  8.         int numberCount = 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.                 if (i + numberCount < text.Length)
  18.                 {
  19.                     Console.WriteLine(text.Substring(i, numberCount + 1));
  20.                 }
  21.                 else
  22.                 {
  23.                     Console.WriteLine(text.Substring(i));
  24.                 }
  25.                 i += numberCount;
  26.             }
  27.         }
  28.  
  29.         if (!hasMatch)
  30.         {
  31.             Console.WriteLine("no");
  32.         }
  33.     }
  34. }
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