A - Array 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).
Receive the integer \(N\), array \(A\), and integer \(X\) in order, and print \(A_X\).
Input of arrays varies language to language. Please refer to sample code or look for information on the Internet.
Also, note that in most programming languages, array index starts with \(0\). (Some languages start with \(0\).)
In such languages,
- The first value is
A[0] - The second value is
A[1]
\(\vdots\)
- The \(N\)-th value is
A[N-1]
Thus, note that you need to write A[X-1] to refer to the \(X\)-th value.
Sample code in Python
n = int(input())
a = list(map(int, input().split())) # a = [int(_) for _ in input().split()] のようにも書けます
x = int(input())
print(a[x-1])
Sample code in C++
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> a(n);
for (int i=0; i<n; i++) cin >> a[i];
int x; cin >> x;
cout << a[x-1] << endl;
}
posted:
last update: