paizaラーニングレベルアップ問題集の「【配列を参照する操作】全ての要素に対する操作」をやってみた。

paizaラーニングレベルアップ問題集の[【配列を参照する操作】全ての要素に対する操作](https://paiza.jp/works/mondai/array_utilization_primer/array_utilization_primer__map)をやってみました。
- - -
###### 問題
https://paiza.jp/works/mondai/array_utilization_primer/array_utilization_primer__map
- - -
###### C
```c
#include <stdio.h>

int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	int A[n];
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	int B[n];
	for (int i = 0; i < n; i++) B[i] = A[i] + k;
	for (int i = 0; i < n; i++) printf("%d\n", B[i]);
	return 0;
}
```
- - -
###### C++
```cpp
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> A(n);
	for (int i = 0; i < n; i++) cin >> A[i];
	vector<int> B(n);
	for (int i = 0; i < n; i++) B[i] = A[i] + k;
	for (int i = 0; i < n; i++) cout << B[i] << endl;
	return 0;
}
```
- - -
###### C#
```cs
using System;
using System.Linq;

class Program
{
	static void Main()
	{
		int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int n = nk[0];
		int k = nk[1];
		int[] A = Enumerable.Range(0, n).Select(_ => int.Parse(Console.ReadLine())).ToArray();
		Array.ForEach(A.Select(a => a + k).ToArray(), Console.WriteLine);
		// 別解
		// A.Select(a => a + k).ToList().ForEach(Console.WriteLine);
	}
}
```
- - -
###### Go
```go
package main
import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	A := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&A[i])
	}
	B := make([]int, n)
	for i := 0; i < n; i++ {
		B[i] = A[i] + k
	}
	for i := 0; i < n; i++ {
		fmt.Println(B[i])
	}
}
```
- - -
###### Java
```java
import java.util.*;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] A = IntStream.range(0, n).map(i -> sc.nextInt()).toArray();
		Arrays.stream(A).map(a -> a + k).forEach(System.out::println);
	}
}
```
- - -
###### JavaScript
```js
const [[n, k], ...A] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map((s, i) => i ? Number(s) : s.split(' ').map(Number));
A.map(a => a + k).forEach(a => console.log(a));
```
- - -
###### Kotlin
```kotlin
fun main() {
	val (n, k) = readLine()!!.split(' ').map { it.toInt() }
	val A = Array(n) { readLine()!!.toInt() }
	val B = A.map { it + k }
	B.forEach { println(it) }
}
```
- - -
###### PHP
```php
<?php
	[$n, $k] = array_map("intval", explode(' ', fgets(STDIN)));
	$A = [];
	for ($i = 0; $i < $n; $i++) $A[] = intval(fgets(STDIN));
	foreach (array_map(fn($a) => $a + $k, $A) as $a) echo $a, PHP_EOL;
?>
```
- - -
###### Perl
```pl
my ($n, $k) = map { int($_) } split ' ', <STDIN>;
my @A;
for (1..$n) {
	push @A, int(<STDIN>);
}
for (map { $_ + $k } @A) {
	print "$_$/";
}
```
- - -
###### Python3
```py
import numpy as np
n, k = map(int, input().split())
print(*np.array(list(int(input()) for _ in range(n))) + k, sep='\n')
```
- - -
###### Ruby
```rb
n, k = gets.split.map(&:to_i)
A = n.times.map { gets.to_i }
A.map { |a| a + k }.each do |a|
	p a
end
```
- - -
###### Scala
```scala
import scala.io.StdIn._

object Main extends App{
	val Array(n, k) = readLine().split(' ').map { _.toInt }
	val A = (0 until n).map { _ => readInt() }
	A.map { _ + k }.foreach(println)
}
```
- - -
###### Swift
```swift
let nk = readLine()!.split(separator: " ").compactMap { Int($0) }
let (n, k) = (nk[0], nk[1])
var A: [Int] = []
for _ in 0..<n {
	A.append(Int(readLine()!)!)
}
A.map { $0 + k }.forEach { print($0) }
```