Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  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[] keys = Console.ReadLine().Split("&");
  13.  
  14. // Regex regex = new Regex(@"^[a-zA-Z0-9]{16,25}$");
  15.  
  16. var result = new List<string>();
  17.  
  18. for (int i = 0; i < keys.Length; i++)
  19. {
  20. // Match matched = regex.Match(keys[i]);
  21. //string sentence = matched.Value;
  22. string sentence = keys[i];
  23. string changedSentence = "";
  24. if ((sentence.Length != 16 && sentence.Length != 25) || !sentence.All(c => char.IsLetterOrDigit(c)))
  25. {
  26. sentence = "";
  27. }
  28. if (sentence != "")
  29. {
  30. if (sentence.Length == 16)
  31. {
  32. for (int j = 4; j < 16; j += 5)
  33. {
  34. sentence = sentence.Insert(j, "-");
  35. }
  36. }
  37. else
  38. {
  39. for (int k = 5; k < 25; k += 6)
  40. {
  41. sentence = sentence.Insert(k, "-");
  42. }
  43. }
  44.  
  45. for (int c = 0; c < sentence.Length; c++)
  46. {
  47. if ((sentence[c] >= '0') && (sentence[c] <= '9'))
  48. {
  49. changedSentence += 9 - (sentence[c] - '0');
  50. }
  51. else
  52. {
  53. changedSentence += sentence[c];
  54. }
  55. }
  56. result.Add(changedSentence.ToUpper());
  57. }
  58. }
  59. Console.WriteLine(string.Join(", ", result));
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement