Advertisement
Aborigenius

1. Find the Letter

Aug 23rd, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace FindtheLetter
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string text = Console.ReadLine();
  14.             string[] search = Console.ReadLine().Split(' ');
  15.  
  16.             string searchLetter = search[0];
  17.             int occurence = int.Parse(search[1]);
  18.             List<int> foundindexes = new List<int>();
  19.  
  20.             for (int i = text.IndexOf(searchLetter); i > -1; i = text.IndexOf(searchLetter, i + 1))
  21.             {
  22.                 foundindexes.Add(i);
  23.             }
  24.  
  25.             if (foundindexes.Count >= occurence)
  26.             {
  27.                 for (int k = 0; k < foundindexes.Count; k++)
  28.                 {
  29.                     if (k == occurence - 1)
  30.                     {
  31.                         Console.WriteLine(foundindexes[k]);
  32.                     }
  33.                 }
  34.             }
  35.             else
  36.             {
  37.                 Console.WriteLine("Find the letter yourself!");
  38.             }
  39.  
  40.  
  41.  
  42.         }
  43.  
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement