結果

問題 No.432 占い(Easy)
ユーザー Maeda
提出日時 2025-04-08 13:21:38
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,900 bytes
コンパイル時間 8,178 ms
コンパイル使用メモリ 171,936 KB
実行使用メモリ 189,084 KB
最終ジャッジ日時 2025-04-08 13:21:50
合計ジャッジ時間 11,359 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (132 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] ansList = Enumerable.Repeat(-1, n).ToArray();
            for (int i = 0; i < n; i++)
            {
                string str = Console.ReadLine();
                int num = 0;
                if (str.Length > 2)
                {
                    List<int> list = new List<int>();
                    for (int j = 0; j < str.Length; j++)
                    {
                        list.Add(int.Parse(str[j].ToString()));
                    }
                    num = RecursionNumber(list, ansList[i]);
                }
                else
                {
                    
                    num = int.Parse(str)/10 + int.Parse(str) % 10;
                }
                while (num >= 10)
                {
                    num = (num / 10) + (num % 10);
                }
                ansList[i] = num;
            }
            for(int i = 0; i < n; i++)
            {
                Console.WriteLine(ansList[i]);
            }
        }

        private static int RecursionNumber(List<int> list,int ans)
        {
            
            List<int> newList = new List<int>();
            for (int i = 1; i < list.Count; i++)
            {
                int num = list[i - 1] + list[i];
                if(num >= 10)
                {
                    num = (num / 10) + (num % 10);
                }
                newList.Add(num);
            }
            if (newList.Count > 2)
            {
                ans = RecursionNumber(newList, ans);
            }
            else
            {
                ans = newList[0] + newList[1];
                if (ans >= 10)
                {
                    ans = (ans / 10) + (ans % 10);
                }

            }

                return ans;

        }
    }
0