Advertisement
Guest User

Untitled

a guest
Apr 9th, 2019
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _02._Activation_Keys
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string[] stringOfInput = Console.ReadLine().Split("&");
  13. List<string> keys = new List<string>();
  14. for (int i = 0; i < stringOfInput.Length; i++)
  15. {
  16. StringBuilder sb = new StringBuilder();
  17. var regex = Regex.Matches(stringOfInput[i], @"[A-Za-z0-9]+[?:(^A-Za-z0-9)]");
  18.  
  19. foreach (Match key in regex)
  20. {
  21. if (key.Length == 16)
  22. {
  23. for (int j = 0; j < key.Length; j++)
  24. {
  25. char keyToAdd = key.ToString().ToUpper()[j];
  26. if (j != 0 && j % 4 == 0)
  27. {
  28. sb.Append("-");
  29. }
  30. if (char.IsDigit(keyToAdd))
  31. {
  32. int a = int.Parse(keyToAdd.ToString());
  33. int newKeys = 9 - a;
  34. sb.Append(newKeys);
  35. }
  36. else
  37. {
  38. sb.Append(keyToAdd);
  39. }
  40. }
  41. keys.Add(sb.ToString());
  42. }
  43. else if (key.Length == 25)
  44. {
  45. for (int j = 0; j < key.Length; j++)
  46. {
  47. char keyToAdd = key.ToString().ToUpper()[j];
  48. if (j != 0 && j % 5 == 0)
  49. {
  50. sb.Append("-");
  51. }
  52. if (char.IsDigit(keyToAdd))
  53. {
  54. int a = int.Parse(keyToAdd.ToString());
  55. int newKeys = 9 - a;
  56. sb.Append(newKeys);
  57. }
  58. else
  59. {
  60. sb.Append(keyToAdd);
  61. }
  62. }
  63. keys.Add(sb.ToString());
  64. }
  65. }
  66. }
  67. Console.WriteLine(String.Join(", ", keys));
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement