Advertisement
Prohause

Snowflake

Aug 10th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace Problem03Exam05012018
  5. {
  6. internal class Program
  7. {
  8. private static void Main(string[] args)
  9. {
  10. const string surfacePattern = @"[^a-zA-Z0-9]+";
  11. const string mantlePattern = @"[0-9_]+";
  12. const string corePattern = @"([a-zA-Z]+)";
  13.  
  14. var core = string.Empty;
  15.  
  16. var input = Console.ReadLine();
  17. var matcher = Regex.Match(input, $@"^{surfacePattern}$");
  18.  
  19. if (!matcher.Success)
  20. {
  21. Console.WriteLine("Invalid");
  22. return;
  23. }
  24.  
  25. input = Console.ReadLine();
  26. matcher = Regex.Match(input, $@"^{mantlePattern}$");
  27.  
  28. if (!matcher.Success)
  29. {
  30. Console.WriteLine("Invalid");
  31. return;
  32. }
  33.  
  34. input = Console.ReadLine();
  35. var linePattern = $@"^{surfacePattern}{mantlePattern}{corePattern}{mantlePattern}{surfacePattern}$";
  36. matcher = Regex.Match(input, linePattern);
  37.  
  38. if (matcher.Success)
  39. {
  40. core = matcher.Groups[1].Value;
  41. }
  42. else
  43. {
  44. Console.WriteLine("Invalid");
  45. return;
  46. }
  47.  
  48. input = Console.ReadLine();
  49. matcher = Regex.Match(input, $@"^{mantlePattern}$");
  50.  
  51. if (!matcher.Success)
  52. {
  53. Console.WriteLine("Invalid");
  54. return;
  55. }
  56.  
  57. input = Console.ReadLine();
  58. matcher = Regex.Match(input, $@"^{surfacePattern}$");
  59.  
  60. if (!matcher.Success)
  61. {
  62. Console.WriteLine("Invalid");
  63. return;
  64. }
  65.  
  66. Console.WriteLine("Valid");
  67. Console.WriteLine(core.Length);
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement