結果

問題 No.1849 Three Times Value
ユーザー bluemegane
提出日時 2023-08-23 20:04:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 759 bytes
コンパイル時間 936 ms
コンパイル使用メモリ 109,412 KB
実行使用メモリ 18,048 KB
最終ジャッジ日時 2024-12-22 04:14:16
合計ジャッジ時間 2,625 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var s = Console.ReadLine().Trim();
        getAns(s);
    }
    static void getAns(string s)
    {
        var n = s.Length;
        if (n % 3 != 0)
        {
            var w = n / 3;
            Console.WriteLine(w > 0 ? new string('9', w) : "0");
        }
        else
        {
            var w = n / 3;
            var ws = s.Substring(0, w);
            var ww = int.Parse(ws);
            var www = long.Parse(ws + ws + ws);
            var ww2 = w > 1 ? int.Parse(new string('9', w - 1)) : 0;
            var ans = ww - (int)Pow(10, w - 1) + 1 + ww2;
            if (www > long.Parse(s)) ans--;
            Console.WriteLine(ans);
        }
    }
}
0