結果

問題 No.933 おまわりさんこいつです
ユーザー Maeda
提出日時 2025-04-01 17:29:09
言語 C#
(.NET 8.0.404)
結果
WA  
実行時間 -
コード長 1,186 bytes
コンパイル時間 7,795 ms
コンパイル使用メモリ 170,536 KB
実行使用メモリ 210,488 KB
最終ジャッジ日時 2025-04-01 17:29:22
合計ジャッジ時間 11,139 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 WA * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (105 ミリ秒)。
  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());
            string num = Console.ReadLine();
            string[] numList = num.Split(' ');
            decimal sum = 0;
            if (numList.Length > 1)
            {
                for (int i = 0; i < n; i++)
                {
                    if (decimal.Parse(numList[i]) % 9 == 0)
                    {
                        sum += 9;
                        continue;
                    }
                    sum += decimal.Parse(numList[i]) % 9;
                }
            }
            else
            {
                sum = decimal.Parse(num);
            }
                Console.WriteLine(NumericRoot(sum.ToString()));
        }

        private static int NumericRoot(string sum)
        {
            string str = sum;
            while (str.Length > 1){
                int num = 0;
                for(int i = 0; i < str.Length; i++)
                {
                    num += int.Parse(str[i].ToString());
                }
                str = num.ToString();
            }

            return int.Parse(str);
        }
    }
0