Advertisement
Guest User

Substring

a guest
Oct 7th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement