Advertisement
angelneychev

Untitled

Apr 9th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _02._Activation_Keys
  7. {
  8.     class Program
  9.     {
  10.         static void Main()
  11.         {
  12.             string inputLine = Console.ReadLine();
  13.             string[] command = inputLine.Split("&");
  14.  
  15.             string serialNumber = string.Empty;
  16.             bool verifyString = true;
  17.             for (int i = 0; i < command.Length; i++)
  18.             {
  19.                 //T8KJZ-U235Z-IME3D-L0RYD-9G8U1, RG06-BXGK-MILW-811M, KROG-F8PR-UDXD-A5LN, U6WH-0KXP-Y9SN-CCFS
  20.                 //t1kjZU764zIME6Dl9ryD0g1U8&-P4*(`Q>:x8\yE1{({X/Hoq!gR.&rg93bXgkmILW188m&KroGf1prUdxdA4ln&U3WH9kXPY0SncCfs
  21.                 string lenOfString = command[i].ToUpper();
  22.                 char[] ii = lenOfString.ToCharArray();
  23.                 int lenght = ii.Length;
  24.                 for (int j = 0; j < ii.Length; j++)
  25.                 {
  26.                     if (!char.IsLetterOrDigit(ii[j]))
  27.                     {
  28.                         verifyString = false;
  29.                         break;
  30.                     }
  31.  
  32.                     verifyString = true;
  33.                 }
  34.                 if (verifyString)
  35.                 {
  36.                     if (lenght ==16)
  37.                     {
  38.                         int count = 0;
  39.                         for (int j = 0; j < ii.Length; j++)
  40.                         {
  41.                             count++;
  42.                             if (char.IsLetter(ii[j]))
  43.                             {
  44.                                 serialNumber += ii[j];
  45.                             }
  46.                             else if (char.IsDigit(ii[j]))
  47.                             {
  48.                                 int newNumber = ii[j];
  49.                                 newNumber = 57 - newNumber;
  50.                                 serialNumber += newNumber;
  51.                             }
  52.  
  53.                             if (count % 4 == 0 && count <ii.Length)
  54.                             {
  55.                                 serialNumber += "-";
  56.                             }
  57.  
  58.                             if (count == ii.Length && (i < command.Length-1))
  59.                             {
  60.                                 serialNumber += ", ";
  61.                             }
  62.                         }
  63.                     }
  64.                    
  65.  
  66.                     if (lenght == 25)
  67.                     {
  68.                         int count = 0;
  69.                         for (int j = 0; j < ii.Length; j++)
  70.                         {
  71.                             count++;
  72.                             if (char.IsLetter(ii[j]))
  73.                             {
  74.                                 serialNumber += ii[j];
  75.                             }
  76.                             else if (char.IsDigit(ii[j]))
  77.                             {
  78.                                 int newNumber = ii[j];
  79.                                 newNumber = 57 - newNumber;
  80.                                 serialNumber += newNumber;
  81.  
  82.                             }
  83.  
  84.                             if (count % 5 == 0 && count < ii.Length)
  85.                             {
  86.                                 serialNumber += "-";
  87.                             }
  88.                             if (count == ii.Length && (i < command.Length - 1))
  89.                             {
  90.                                 serialNumber += ", ";
  91.                             }
  92.                         }
  93.                     }
  94.                 }
  95.             }
  96.  
  97.             Console.WriteLine(serialNumber);
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement