1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【AtCoder C++】ABC081B - Shift Only

Last updated at Posted at 2024-03-06

AtCoder 学習記録用 B shift only ABC081B -shift only

#include <bits/stdc++.h>
using namespace std;

int main(){
  int N,A[200],count=0;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  //偶数判定フラグ
  bool allEven = true;
  //繰り返し
  while(1){
    //A[200]に対して、%2==0なら2で割る。それ以外は、allEven=False
    for(int i = 0; i < N; i++){
      if(A[i] % 2 == 0){
        A[i] = A[i] / 2;
      }else{
        allEven = false;
        break;
      }
    }
    //falseだったらcountそのまま出力して終了
    if(!allEven){
      cout << count << endl;
      return 0;
    }else{
      count++;
    }
  }
}

初見考えても分からなかったので、解く方針を他の記事に参照してもらいました。

初めて知ったこと

  • int A[要素数]で配列定義できること
  • while(1)で無限ループ。1=trueだから。ブロック内でbreakやreturnする必要あり
  • 複数の数値の標準入力を受け付ける際には、配列定義とfor (int i = 0; i < N; i++){ cin >> A[i]; } でできたこと!

参考文献

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?