Official
A - Adjacent Product Editorial by yuto1115
解説AtCoder をはじめたばかりで何をしたらよいか分からない方は、まずは practice contest の問題A「Welcome to AtCoder」を解いてみてください。基本的な入出力の方法が載っています。
また、プログラミングコンテストの問題に慣れていない方は、AtCoder Beginners Selection の問題をいくつか解いてみることをおすすめします。
入出力、四則演算、配列、for 文を用いた繰り返し処理などの基礎的な言語機能の使い方を問う問題です。問題文の指示に従って、数列 \(A\) を入力として受け取り、数列 \(B\) を計算し、\(B\) を出力してください。
具体的な実装方法は下記の実装例 (C++, Python) を参考にしてください。
実装例 (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');
}
}
実装例 (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)
posted:
last update: