using System; using System.Collections.Generic; using System.Linq; namespace YukiCoderNo233 { class Program { static void Main() { string targetName = "inabameguru"; char[] targetNameArray = targetName.ToCharArray(); int targetNameArrayCount = targetNameArray.Count(); Dictionary charactorList = new Dictionary(); Dictionary> charctorCheckList = new Dictionary>(); int vowelCount = 0; int consonantCount = 0; int plusValue = 0; for (int i = 0; i < targetNameArrayCount; i++) { char buffer = targetNameArray[i]; if (IsVowel(buffer)) { vowelCount++; } else { consonantCount++; } if (charactorList.ContainsKey(buffer)) { charactorList[buffer]++; } else { charactorList.Add(buffer, 1); charctorCheckList.Add(buffer, new Dictionary()); } } if (vowelCount > consonantCount) { plusValue = vowelCount - consonantCount; consonantCount += plusValue; charactorList.Add('=', plusValue); charctorCheckList.Add('=', new Dictionary()); } int maxValue = GetFactorialValue(vowelCount) * GetFactorialValue(consonantCount); foreach (int buffer in charactorList.Values) { maxValue /= GetFactorialValue(buffer); } int inputValue = int.Parse(Console.ReadLine()); if (inputValue == 0) { Console.WriteLine("{0}", targetName); } else if (inputValue < maxValue) { string[] nameList = new string[inputValue]; for (int i = 0; i < inputValue; i++) { nameList[i] = Console.ReadLine(); string nowName = nameList[i]; int nowTargetNameArrayCount = targetNameArrayCount; if (IsVowel(nowName[0])) { nowName = "=" + nowName; nowTargetNameArrayCount++; } for (int j = 1; j < nowTargetNameArrayCount; j++) { if (IsVowel(nowName[j]) && (IsVowel(nowName[j - 1]))) { nowName = nowName.Insert(j, "="); j++; nowTargetNameArrayCount++; } } char[] buffer = nowName.ToCharArray(); for (int j = 0; j < nowTargetNameArrayCount; j++) { Dictionary targetCharactorInfo = charctorCheckList[buffer[j]]; if (targetCharactorInfo.ContainsKey(j)) { targetCharactorInfo[j]++; } else { targetCharactorInfo.Add(j, 1); bool isVowel = IsVowel(buffer[j]); foreach (char charBuffer in charctorCheckList.Keys) { if ((isVowel == IsVowel(charBuffer)) && (!(charctorCheckList[charBuffer].ContainsKey(j)))) { charctorCheckList[charBuffer].Add(j, 0); } } } } } int generatedNameCount = targetNameArrayCount + plusValue; for (int i = 0; i < maxValue; i++) { char[] generatedName = new char[generatedNameCount]; bool[] usedFlag = new bool[generatedNameCount]; foreach (char buffer in charctorCheckList.Keys) { int useCount = charactorList[buffer]; int j = 0; var sortedList = charctorCheckList[buffer].OrderBy(value => value.Value); foreach (var sortedBuffer in sortedList) { if (usedFlag[sortedBuffer.Key] == false) { usedFlag[sortedBuffer.Key] = true; generatedName[sortedBuffer.Key] = buffer; charctorCheckList[buffer][sortedBuffer.Key]++; j++; if (j >= useCount) { break; } } } } string answer = (new String(generatedName)).Replace("=", ""); if (!(nameList.Contains(answer))) { Console.WriteLine("{0}", answer); break; } } } else { Console.WriteLine("NO"); } } private static bool IsVowel(char targetCharactor) { bool ret = false; if ((targetCharactor == 'a') || (targetCharactor == 'i') || (targetCharactor == 'u') || (targetCharactor == 'e') || (targetCharactor == 'o')) { ret = true; } return ret; } private static int GetFactorialValue(int number) { int ret = 1; for (int i = number; i > 1; i--) { ret *= i; } return ret; } } }