using System.Collections.Generic;
public class LicenseKeyFormatter
public string FormatLicenseKey(string input)
input = CleanInput(input);
string formattedKey = AdjustForTimeOfDay(input);
char separator = DetermineSeparator(input);
formattedKey = AdjustCaseBasedOnVowels(formattedKey);
int sectionLength = DetermineSectionLength(formattedKey);
formattedKey = SplitIntoSections(formattedKey, sectionLength, separator);
formattedKey = ReverseSectionsIfNeeded(formattedKey);
private string CleanInput(string input)
return new string(input.Where(c => char.IsLetterOrDigit(c) || c == '-' || c == '_' || c == ' ').ToArray());
private string AdjustForTimeOfDay(string input)
var hour = DateTime.Now.Hour;
private char DetermineSeparator(string input)
if (input.Any(char.IsDigit))
private string AdjustCaseBasedOnVowels(string input)
string vowels = "aeiouAEIOU";
return new string(input.Select(c =>
vowels.Contains(c) ? char.ToUpper(c) : char.ToLower(c)).ToArray());
private int DetermineSectionLength(string input)
var uniqueChars = input.Distinct().ToList();
return Math.Min(uniqueChars.Count, 4);
private string SplitIntoSections(string input, int sectionLength, char separator)
var sections = new List<string>();
for (int i = 0; i < input.Length; i += sectionLength)
string section = input.Substring(i, Math.Min(sectionLength, input.Length - i));
return string.Join(separator.ToString(), sections);
private string ReverseSectionsIfNeeded(string formattedKey)
if (DateTime.Now.Second % 2 == 0)
var sections = formattedKey.Split('-').ToList();
return string.Join("-", sections);
public static void Main(string[] args)
var formatter = new LicenseKeyFormatter();
Console.WriteLine("Please enter the license key:");
string input = Console.ReadLine();
string formattedKey = formatter.FormatLicenseKey(input);
Console.WriteLine("\nFormatted License Key:");
Console.WriteLine(formattedKey);