Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace _02._Activation_Keys
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] keys = Console.ReadLine().Split("&");
- // Regex regex = new Regex(@"^[a-zA-Z0-9]{16,25}$");
- var result = new List<string>();
- for (int i = 0; i < keys.Length; i++)
- {
- // Match matched = regex.Match(keys[i]);
- //string sentence = matched.Value;
- string sentence = keys[i];
- string changedSentence = "";
- if ((sentence.Length != 16 && sentence.Length != 25) || !sentence.All(c => char.IsLetterOrDigit(c)))
- {
- sentence = "";
- }
- if (sentence != "")
- {
- if (sentence.Length == 16)
- {
- for (int j = 4; j < 16; j += 5)
- {
- sentence = sentence.Insert(j, "-");
- }
- }
- else
- {
- for (int k = 5; k < 25; k += 6)
- {
- sentence = sentence.Insert(k, "-");
- }
- }
- for (int c = 0; c < sentence.Length; c++)
- {
- if ((sentence[c] >= '0') && (sentence[c] <= '9'))
- {
- changedSentence += 9 - (sentence[c] - '0');
- }
- else
- {
- changedSentence += sentence[c];
- }
- }
- result.Add(changedSentence.ToUpper());
- }
- }
- Console.WriteLine(string.Join(", ", result));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement