Advertisement
bullit3189

Santa's Secret Helper 100/100

Mar 13th, 2019
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Text;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. int key = int.Parse(Console.ReadLine());
  12.  
  13. string pattern = @"@(?<name>[A-Za-z]+)([^-@!:>]+)?![G]!";
  14.  
  15. List<string>kids = new List<string>();
  16.  
  17. while(true)
  18. {
  19. string command = Console.ReadLine();
  20.  
  21. if(command == "end")
  22. {
  23. break;
  24. }
  25.  
  26. string input = string.Empty;
  27.  
  28. for (int i=0; i<command.Length; i++)
  29. {
  30. char curr = command[i];
  31.  
  32. if (char.IsDigit(curr))
  33. {
  34. int currAsNum = int.Parse(curr.ToString());
  35. currAsNum-=key;
  36. input += currAsNum;
  37. }
  38. else
  39. {
  40. int currAsNum = (int)curr;
  41. currAsNum-=key;
  42. char toAdd = (char)currAsNum;
  43. input += toAdd;
  44. }
  45. }
  46.  
  47. if (Regex.IsMatch(input,pattern))
  48. {
  49. Match match = Regex.Match(input,pattern);
  50.  
  51. string name = match.Groups["name"].Value;
  52.  
  53. kids.Add(name);
  54. }
  55. }
  56.  
  57. foreach (string name in kids)
  58. {
  59. Console.WriteLine(name);
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement