Official

A - Sequence of Strings Editorial by en_translator


If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).


Use a for statement to follow the instructions in the Problem Statement. See the sample codes below for the implementation.

C++

#include<bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector <string> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = n - 1; i >= 0; i--) cout << s[i] << endl;
}

Python

n = int(input())

s = []

for i in range(n):
    si = input()
    s.append(si)
  
for i in range(n):
    print(s[-(i + 1)])

This sample code uses a feature of Python that enables us to specify \(-i\) as an index of an array to access its \(i\)-th last element.

posted:
last update: