Again_89

Activation Keys

Apr 13th, 2019
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. namespace _02._Activation_Keys
  7. {
  8. class Program
  9. {
  10. static void Main()
  11. {
  12. var input = Console.ReadLine().Split("&");
  13. var result = new List<string>();
  14.  
  15. for (int i = 0; i < input.Length; i++)
  16. {
  17. var firstPattern = @"^[a-zA-Z0-9]{16}$";
  18. var secondPattern = @"^[a-zA-Z0-9]{25}$";
  19.  
  20. if (Regex.IsMatch(input[i], firstPattern) || Regex.IsMatch(input[i], secondPattern))
  21. {
  22. var word = input[i].ToUpper().ToList();
  23. for (int j = 0; j < word.Count; j++)
  24. {
  25. if (char.IsDigit(word[j]))
  26. {
  27. var symbol = (9 - int.Parse(word[j].ToString())).ToString();
  28. var symbolInChar = Convert.ToChar(symbol);
  29. word[j] = symbolInChar;
  30. }
  31. }
  32. if (word.Count == 16)
  33. {
  34. word.Insert(4, '-');
  35. word.Insert(9, '-');
  36. word.Insert(14, '-');
  37. }
  38. else if (word.Count == 25)
  39. {
  40. word.Insert(5, '-');
  41. word.Insert(11, '-');
  42. word.Insert(17, '-');
  43. word.Insert(23, '-');
  44. }
  45.  
  46. var wordInString = new string(word.ToArray());
  47. result.Add(wordInString);
  48. }
  49. }
  50.  
  51. Console.WriteLine(string.Join(", ", result));
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment