using System; using System.Collections.Generic; using System.Text; namespace D11._1 { class Program { static string Increment(string input) { if (input.Length == 0) return input; StringBuilder sb = new StringBuilder(); var pos = input.Length - 1; var nchar = input[pos] + 1; if (nchar == 'i' || nchar == 'l' || nchar == 'o') nchar++; if (nchar > 'z') { nchar = 'a'; var inc = Increment(input.Substring(0, pos)); sb.Append(inc); sb.Append((char) nchar); } else { sb.Append(input.Substring(0, pos)); sb.Append((char) nchar); } return sb.ToString(); } static bool IsValid(string pwd) { bool hasIncreasing = false; bool hasForbiddenLettres = false; int repetitions = 0; bool repetitionExists = false; char last = '\0', lalast = '\0'; int same = 1; foreach (var c in pwd) { if (c == 'i' || c == 'l' || c == 'o') { hasForbiddenLettres = true; break; } if (c == last) same++; else same = 1; if (same == 4) repetitionExists = true; if (repetitionExists == false && same == 2) { repetitions++; repetitionExists = repetitions >= 2; } if (lalast + 1 == last && last + 1 == c) hasIncreasing = true; lalast = last; last = c; } return hasForbiddenLettres == false && hasIncreasing && repetitionExists; } static void Main(string[] args) { if (args.Length < 1) throw new ArgumentException(); string input = args[0]; input = NexPassword(input); Console.WriteLine($"The next password is : {input}"); input = NexPassword(input); Console.WriteLine($"The next password is : {input}"); } private static string NexPassword(string input) { bool isValid = false; do { input = Increment(input); isValid = IsValid(input); } while (isValid == false); return input; } } }