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

More than 1 year has passed since last update.

[Atcoder備忘録記事]AtCoder Beginner Contest 344 B問題

Last updated at Posted at 2024-04-02

問題

image.png

入出力例

image.png

解法

Nは与えられないので制約にある通り初期値を100にします。
0が$A_i \neq 0 \quad (1 \leq i \leq N - 1)$と$A_N = 0$の制約があるので0をみつけたらループを中断し、その時点での$i$のインデックスを保存します。
後は保存したインデックスから逆向きにforループを回して終了です。

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
    vector<int> N(100);
    int punctuation = 0;
    for(int i = 0; i <= 100; i++){
        cin >> N.at(i);
        if(N.at(i) == 0){
            punctuation  = i;
            i = 100;
        }
    }
    for(int i = punctuation; i >= 0; i--){
        cout << N.at(i) << endl;
    }
}
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?