Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace _02._Activation_Keys
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] stringOfInput = Console.ReadLine().Split("&");
- List<string> keys = new List<string>();
- for (int i = 0; i < stringOfInput.Length; i++)
- {
- StringBuilder sb = new StringBuilder();
- var regex = Regex.Matches(stringOfInput[i], @"[A-Za-z0-9]+[?:(^A-Za-z0-9)]");
- foreach (Match key in regex)
- {
- if (key.Length == 16)
- {
- for (int j = 0; j < key.Length; j++)
- {
- char keyToAdd = key.ToString().ToUpper()[j];
- if (j != 0 && j % 4 == 0)
- {
- sb.Append("-");
- }
- if (char.IsDigit(keyToAdd))
- {
- int a = int.Parse(keyToAdd.ToString());
- int newKeys = 9 - a;
- sb.Append(newKeys);
- }
- else
- {
- sb.Append(keyToAdd);
- }
- }
- keys.Add(sb.ToString());
- }
- else if (key.Length == 25)
- {
- for (int j = 0; j < key.Length; j++)
- {
- char keyToAdd = key.ToString().ToUpper()[j];
- if (j != 0 && j % 5 == 0)
- {
- sb.Append("-");
- }
- if (char.IsDigit(keyToAdd))
- {
- int a = int.Parse(keyToAdd.ToString());
- int newKeys = 9 - a;
- sb.Append(newKeys);
- }
- else
- {
- sb.Append(keyToAdd);
- }
- }
- keys.Add(sb.ToString());
- }
- }
- }
- Console.WriteLine(String.Join(", ", keys));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement