Advertisement
Guest User

Untitled

a guest
Apr 8th, 2019
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _02._Activation_Keys
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string input = Console.ReadLine();
  11.             string[] inputAsArray = input.Split("&");
  12.             List<string> keys = new List<string>();
  13.  
  14.             for (int i = 0; i < inputAsArray.Length; i++)
  15.             {
  16.                 bool isValdKey = true;
  17.  
  18.                 if (inputAsArray[i].Length == 16 || inputAsArray[i].Length == 25)
  19.                 {
  20.                     for (int j = 0; j < inputAsArray[i].Length; j++)
  21.                     {
  22.                         if (!char.IsLetterOrDigit(inputAsArray[i][j]))
  23.                         {
  24.                             isValdKey = false;
  25.                         }
  26.                     }
  27.                     if (isValdKey)
  28.                     {
  29.                         keys.Add(inputAsArray[i].ToUpper());
  30.                     }
  31.                 }
  32.             }
  33.  
  34.             for (int i = 0; i < keys.Count; i++)
  35.             {
  36.                 if (keys[i].Length == 16)
  37.                 {
  38.                     string temp = string.Empty;
  39.  
  40.                     for (int j = 0; j < keys[i].Length; j++)
  41.                     {
  42.                         temp += keys[i][j];
  43.                         if ((j + 1) % 4 == 0 && j != 15)
  44.                         {
  45.                             temp += "-";
  46.                         }
  47.                     }
  48.                     keys[i] = temp;
  49.                 }
  50.  
  51.                 else if (keys[i].Length == 25)
  52.                 {
  53.                     string temp = string.Empty;
  54.  
  55.                     for (int j = 0; j < keys[i].Length; j++)
  56.                     {
  57.                         temp += keys[i][j];
  58.                         if ((j + 1) % 5 == 0 && j != 24)
  59.                         {
  60.                             temp += "-";
  61.                         }
  62.                     }
  63.                     keys[i] = temp;
  64.                 }
  65.             }
  66.  
  67.             for (int i = 0; i < keys.Count; i++)
  68.             {
  69.                 string temp = string.Empty;
  70.                 for (int j = 0; j < keys[i].Length; j++)
  71.                 {
  72.  
  73.                     if (char.IsDigit(keys[i][j]))
  74.                     {
  75.                        
  76.                         int num = (9 - int.Parse(keys[i][j].ToString()));
  77.                         temp = string.Concat(temp, num);
  78.                     }
  79.                     else
  80.                     {
  81.                         temp += keys[i][j];
  82.                     }
  83.                 }
  84.                 keys[i] = temp;
  85.             }
  86.             Console.WriteLine(string.Join(", ", keys));
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement