LoginSignup
0
0

More than 3 years have passed since last update.

C#でAtCoder Beginners Selection(ABC081B - Shift only)

Last updated at Posted at 2021-01-20

準備

C#でAtCoderデビューのための準備
のあとで AtCoder Beginners Selection をやってみました。

問題文

ABC081B - Shift only
https://atcoder.jp/contests/abs/tasks/abc081_b

提出結果

using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        string[] value = Console.ReadLine().Split(' ');
        var a = Enumerable.Repeat(0, n).ToArray();
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(value[i]);
        }
        int kaisuu = 0;
        bool owari = false;
        while (owari == false)
        {
            for (int i = 0; i < n; i++)
            {
                int amari = a[i] % 2;
                if (amari == 0)
                {
                    a[i] = a[i] / 2;
                }
                else
                {
                    owari = true;
                    break;
                }
            }
            if (!owari) kaisuu++;
        }
        Console.WriteLine($"{kaisuu}");
    }
}

テスト実行

image.png
image.png
image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0