公式

A - Adjacent Product 解説 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).


This problem requires basic language features like input, output, arithmetic operations, arrays, and loop using for statements. Following the instruction in the problem statement, receive the sequence \(A\) as input, compute the sequence \(B\), and print \(B\).

For specific implementation, refer to the sample code (C++ and Python) below.

Sample code (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];
    }
    for (int i = 0; i < n - 1; i++) {
        int b = a[i] * a[i + 1];
        cout << b << (i + 1 < n ? ' ' : '\n');
    }
}

Sample code (Python):

n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n - 1):
    b.append(a[i] * a[i + 1])
print(*b)

投稿日時:
最終更新: