Official

B - Delimiter Editorial by en_translator


This problem requires two tasks:

  • Repeatedly read \(A_i\) until reading \(0\).
  • Print \(A_i\) in the reverse order.

For example, the former can be achieved with a while statement, and the second with a for statement where the index is decremented.

Sample code (C++):

#include<bits/stdc++.h>

using namespace std;

int main(){
  vector<int> a;
  while(true){
    int ca;
    cin >> ca;
    a.push_back(ca);
    if(ca==0){break;}
  }
  for(int i=a.size()-1;i>=0;i--){
    cout << a[i] << "\n";
  }
  return 0;
}

posted:
last update: