Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- using System.Linq;
- using System.Collections.Generic;
- namespace _02._Activation_Keys
- {
- class Program
- {
- static void Main()
- {
- var input = Console.ReadLine().Split("&");
- var result = new List<string>();
- for (int i = 0; i < input.Length; i++)
- {
- var firstPattern = @"^[a-zA-Z0-9]{16}$";
- var secondPattern = @"^[a-zA-Z0-9]{25}$";
- if (Regex.IsMatch(input[i], firstPattern) || Regex.IsMatch(input[i], secondPattern))
- {
- var word = input[i].ToUpper().ToList();
- for (int j = 0; j < word.Count; j++)
- {
- if (char.IsDigit(word[j]))
- {
- var symbol = (9 - int.Parse(word[j].ToString())).ToString();
- var symbolInChar = Convert.ToChar(symbol);
- word[j] = symbolInChar;
- }
- }
- if (word.Count == 16)
- {
- word.Insert(4, '-');
- word.Insert(9, '-');
- word.Insert(14, '-');
- }
- else if (word.Count == 25)
- {
- word.Insert(5, '-');
- word.Insert(11, '-');
- word.Insert(17, '-');
- word.Insert(23, '-');
- }
- var wordInString = new string(word.ToArray());
- result.Add(wordInString);
- }
- }
- Console.WriteLine(string.Join(", ", result));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment