Advertisement
Guest User

Untitled

a guest
Dec 28th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace NthChar
  5. {
  6. public class StartUp
  7. {
  8. public static void Main()
  9. {
  10. string input = Console.ReadLine();
  11. string[] data = Console.ReadLine().Split();
  12. char charToFind = data[0][0];
  13. int occurrences = int.Parse(data[1]);
  14.  
  15. var result = input.Select((c, i) => new { Char = c, Index = i })
  16. .Where(item => item.Char == charToFind)
  17. .Skip(occurrences - 1)
  18. .FirstOrDefault();
  19.  
  20. Console.WriteLine(result?.Index.ToString()?? "Find the letter yourself!");
  21.  
  22. }
  23.  
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement