結果

問題 No.47 ポケットを叩くとビスケットが2倍
ユーザー nanophoto12
提出日時 2014-11-01 16:46:14
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 850 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 103,168 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-12-30 16:02:44
合計ジャッジ時間 2,719 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

class Program
{
    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        if (n == 1)
        {
            Console.WriteLine(0);
            return;
        }
        bool[] bits = new bool[32];
        int maxBits = 0;
        for(int i = 0; i < 32;i++)
        {
            if ((n & (1 << i)) == 1 << i)
            {
                bits[i] = true;
                maxBits = Math.Max(maxBits, i);
            }
        }
        bool hasMore = false;
        for (int i = maxBits-1; i >= 0; i--)
        {
            if (bits[i])
            {
                hasMore = true;
            }
        }
        if (hasMore)
        {
            Console.WriteLine(maxBits+1);
            return;
        }
        Console.WriteLine(maxBits);
    }
}
0