結果

問題 No.233 めぐるはめぐる (3)
ユーザー nokonokonokonoko
提出日時 2015-07-02 22:34:01
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 5,652 bytes
コンパイル時間 4,978 ms
コンパイル使用メモリ 106,968 KB
実行使用メモリ 35,932 KB
最終ジャッジ日時 2023-09-22 05:43:49
合計ジャッジ時間 10,875 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 312 ms
31,804 KB
testcase_01 AC 220 ms
30,140 KB
testcase_02 AC 152 ms
29,324 KB
testcase_03 AC 252 ms
32,232 KB
testcase_04 AC 301 ms
35,932 KB
testcase_05 AC 305 ms
33,896 KB
testcase_06 AC 308 ms
33,956 KB
testcase_07 AC 65 ms
21,640 KB
testcase_08 AC 65 ms
21,616 KB
testcase_09 WA -
testcase_10 AC 83 ms
20,012 KB
testcase_11 WA -
testcase_12 AC 224 ms
32,196 KB
testcase_13 AC 361 ms
31,980 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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<char, int> charactorList = new Dictionary<char, int>();
            Dictionary<char, Dictionary<int, int>> charctorCheckList = new Dictionary<char, Dictionary<int, int>>();

            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<int, int>());
                }
            }
            if (vowelCount > consonantCount)
            {
                plusValue = vowelCount - consonantCount;
                consonantCount += plusValue;
                charactorList.Add('=', plusValue);
                charctorCheckList.Add('=', new Dictionary<int, int>());
            }
            int maxValue = GetFactorialValue(vowelCount) * GetFactorialValue(consonantCount);
            foreach (int buffer in charactorList.Values)
            {
                maxValue /= GetFactorialValue(buffer);
            }
            int inputValue = int.Parse(Console.ReadLine());
            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<int, int> targetCharactorInfo = charctorCheckList[buffer[j]];
                        if (targetCharactorInfo.ContainsKey(j))
                        {
                            targetCharactorInfo[j]++;
                        }
                        else
                        {
                            targetCharactorInfo.Add(j, 1);
                        }
                    }
                }
                int generatedNameCount = targetNameArrayCount + plusValue;
                for (int i = 0; i < inputValue; 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;
        }
    }
}
0