paizaラーニングレベルアップ問題集の【二次元配列の入力】をやってみました。

paizaラーニングレベルアップ問題集の【二次元配列の入力】をやってみました。
- - -
##### 問題
###### STEP: 1
https://paiza.jp/works/mondai/array_primer/array_primer__2dmatrix_input_step1
###### STEP: 2
https://paiza.jp/works/mondai/array_primer/array_primer__2dmatrix_input_step2
###### STEP: 3
https://paiza.jp/works/mondai/array_primer/array_primer__2dmatrix_input_step3
###### STEP: 4
https://paiza.jp/works/mondai/array_primer/array_primer__2dmatrix_input_step4
- - -
##### C
###### STEP: 1
```c
#include <stdio.h>
#define N (2)
#define M (4)

int main() {
	int A[N][M] = { { 1, 3, 5, 7 }, { 8, 1, 3, 8 } };
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (j) putchar(' ');
			printf("%d", A[i][j]);
		}
		puts("");
	}
	return 0;
}
```
###### STEP: 2
```c
#include <stdio.h>

int main() {
	int n = 5;
	int m;
	scanf("%d", &m);
	int A[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			scanf("%d", &A[i][j]);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (j) putchar(' ');
			printf("%d", A[i][j]);
		}
		puts("");
	}
	return 0;
}
```
###### STEP: 3
```c
#include <stdio.h>

int main() {
	int n;
	int m = 5;
	scanf("%d", &n);
	int A[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			scanf("%d", &A[i][j]);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (j) putchar(' ');
			printf("%d", A[i][j]);
		}
		puts("");
	}
	return 0;
}
```
###### STEP: 4
```c
#include <stdio.h>

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	int A[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			scanf("%d", &A[i][j]);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (j) putchar(' ');
			printf("%d", A[i][j]);
		}
		puts("");
	}
	return 0;
}
```
- - -
##### C++
###### STEP: 1
```cpp
#include <iostream>
using namespace std;

const int N = 2;
const int M = 4;

int main() {
	int A[N][M] = { { 1, 3, 5, 7 }, { 8, 1, 3, 8 } };
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (j) cout << ' ';
			cout << A[i][j];
		}
		cout << endl;
	}
	return 0;
}
```
###### STEP: 2
```cpp
#include <iostream>
using namespace std;

int main() {
	int n = 5;
	int m;
	cin >> m;
	int A[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> A[i][j];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (j) cout << ' ';
			cout << A[i][j];
		}
		cout << endl;
	}
	return 0;
}
```
###### STEP: 3
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	int m = 5;
	cin >> n;
	int A[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> A[i][j];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (j) cout << ' ';
			cout << A[i][j];
		}
		cout << endl;
	}
	return 0;
}
```
###### STEP: 4
```cpp
#include <iostream>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int A[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> A[i][j];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (j) cout << ' ';
			cout << A[i][j];
		}
		cout << endl;
	}
	return 0;
}
```
- - -
##### C#
###### STEP: 1
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = 2;
		int m = 4;
		int[][] A = { new int[]{ 1, 3, 5, 7 }, new int[]{ 8, 1, 3, 8 } };
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (j > 0) Console.Write(' ');
				Console.Write(A[i][j]);
			}
			Console.WriteLine();
		}
	}
}
```
###### STEP: 2
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = 5;
		int m = int.Parse(Console.ReadLine());
		int[][] A = new int[n][];
		for (int i = 0; i < n; i++) A[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (j > 0) Console.Write(' ');
				Console.Write(A[i][j]);
			}
			Console.WriteLine();
		}
	}
}
```
###### STEP: 3
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		int m = 5;
		int[][] A = new int[n][];
		for (int i = 0; i < n; i++) A[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (j > 0) Console.Write(' ');
				Console.Write(A[i][j]);
			}
			Console.WriteLine();
		}
	}
}
```
###### STEP: 4
```cs
using System;

class Program
{
	public static void Main()
	{
		int[] nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int n = nm[0], m = nm[1];
		int[][] A = new int[n][];
		for (int i = 0; i < n; i++) A[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (j > 0) Console.Write(' ');
				Console.Write(A[i][j]);
			}
			Console.WriteLine();
		}
	}
}
```
- - -
##### Go
###### STEP: 1
```go
package main
import "fmt"

func main() {
	n := 2
	m := 4
	A := [][]int{ []int{ 1, 3, 5, 7 }, []int{ 8, 1, 3, 8 } }
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(A[i][j])
		}
		fmt.Println()
	}
}
```
###### STEP: 2
```go
package main
import "fmt"

func main() {
	n := 5
	var m int
	fmt.Scan(&m)
	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Scan(&A[i][j])
		}
	}	
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(A[i][j])
		}
		fmt.Println()
	}
}
```
###### STEP: 3
```go
package main
import "fmt"

func main() {
	var n int
	m := 5
	fmt.Scan(&n)
	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Scan(&A[i][j])
		}
	}	
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(A[i][j])
		}
		fmt.Println()
	}
}
```
###### STEP: 4
```go
package main
import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	A := make([][]int, n)
	for i := 0; i < n; i++ {
		A[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Scan(&A[i][j])
		}
	}	
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(A[i][j])
		}
		fmt.Println()
	}
}
```
- - -
##### Java
###### STEP: 1
```java
public class Main {
	public static void main(String[] args) {
		int n = 2;
		int m = 4;
		int[][] A = { { 1, 3, 5, 7 }, { 8, 1, 3, 8 } };
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (j > 0) System.out.print(' ');
				System.out.print(A[i][j]);
			}
			System.out.println();
		}
	}
}
```
###### STEP: 2
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = 5;
		int m = sc.nextInt();
		sc.nextLine();
		int[][] A = new int[n][];
		for (int i = 0; i < n; i++)
			A[i] = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		sc.close();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (j > 0) System.out.print(' ');
				System.out.print(A[i][j]);
			}
			System.out.println();
		}
	}
}
```
###### STEP: 3
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = 5;
		sc.nextLine();
		int[][] A = new int[n][];
		for (int i = 0; i < n; i++)
			A[i] = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		sc.close();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (j > 0) System.out.print(' ');
				System.out.print(A[i][j]);
			}
			System.out.println();
		}
	}
}
```
###### STEP: 4
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.nextLine();
		int[][] A = new int[n][];
		for (int i = 0; i < n; i++)
			A[i] = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		sc.close();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (j > 0) System.out.print(' ');
				System.out.print(A[i][j]);
			}
			System.out.println();
		}
	}
}
```
- - -
##### JavaScript
###### STEP: 1
```js
const N = 2;
const M = 4;
const A = [ [ 1, 3, 5, 7 ], [ 8, 1, 3, 8 ] ];
for (var i = 0; i < N; i++) {
	let s = "";
	for (var j = 0; j < M; j++) {
		if (j) s += ' ';
		s += A[i][j];
	}
	console.log(s);
}
```
###### STEP: 2
```js
const N = 5;
const [M, ...A] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map((s, i) => i ? s.split(' ').map(Number) : Number(s));
for (var i = 0; i < N; i++) {
	let s = "";
	for (var j = 0; j < M; j++) {
		if (j) s += ' ';
		s += A[i][j];
	}
	console.log(s);
}
```
###### STEP: 3
```js
const M = 5;
const [N, ...A] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map((s, i) => i ? s.split(' ').map(Number) : Number(s));
for (var i = 0; i < N; i++) {
	let s = "";
	for (var j = 0; j < M; j++) {
		if (j) s += ' ';
		s += A[i][j];
	}
	console.log(s);
}
```
###### STEP: 4
```js
const [[N, M], ...A] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map(s => s.split(' ').map(Number));
for (var i = 0; i < N; i++) {
	let s = "";
	for (var j = 0; j < M; j++) {
		if (j) s += ' ';
		s += A[i][j];
	}
	console.log(s);
}
```
- - -
##### Kotlin
###### STEP: 1
```kotlin
fun main() {
	val N = 2
	val M = 4
	val A = arrayOf(arrayOf(1, 3, 5, 7), arrayOf(8, 1, 3, 8))
	for (i in 0 until N) {
		for (j in 0 until M) {
			if (j > 0) print(' ')
			print(A[i][j])
		}
		println()
	}
}
```
###### STEP: 2
```kotlin
fun main() {
	val N = 5
	val M = readLine()!!.toInt()
	val A = Array(N) { readLine()!!.split(' ').map { it.toInt() } }
	for (i in 0 until N) {
		for (j in 0 until M) {
			if (j > 0) print(' ')
			print(A[i][j])
		}
		println()
	}
}
```
###### STEP: 3
```kotlin
fun main() {
	val N = readLine()!!.toInt()
	val M = 5
	val A = Array(N) { readLine()!!.split(' ').map { it.toInt() } }
	for (i in 0 until N) {
		for (j in 0 until M) {
			if (j > 0) print(' ')
			print(A[i][j])
		}
		println()
	}
}
```
###### STEP: 4
```kotlin
fun main() {
	val (N, M) = readLine()!!.split(' ').map { it.toInt() }
	val A = Array(N) { readLine()!!.split(' ').map { it.toInt() } }
	for (i in 0 until N) {
		for (j in 0 until M) {
			if (j > 0) print(' ')
			print(A[i][j])
		}
		println()
	}
}
```
- - -
##### PHP
###### STEP: 1
```php
<?php
	$N = 2;
	$M = 4;
	$A = [ [ 1, 3, 5, 7 ], [ 8, 1, 3, 8 ] ];
	for ($i = 0; $i < $N; $i++) {
		for ($j = 0; $j < $M; $j++) {
			if ($j) echo ' ';
			echo $A[$i][$j];
		}
		echo PHP_EOL;
	}
?>
```
###### STEP: 2
```php
<?php
	$N = 5;
	$M = intval(fgets(STDIN));
	$A = [];
	for ($i = 0; $i < $N; $i++) $A[] = array_map("intval", explode(' ', fgets(STDIN)));
	for ($i = 0; $i < $N; $i++) {
		for ($j = 0; $j < $M; $j++) {
			if ($j) echo ' ';
			echo $A[$i][$j];
		}
		echo PHP_EOL;
	}
?>
```
###### STEP: 3
```php
<?php
	$N = intval(fgets(STDIN));
	$M = 5;
	$A = [];
	for ($i = 0; $i < $N; $i++) $A[] = array_map("intval", explode(' ', fgets(STDIN)));
	for ($i = 0; $i < $N; $i++) {
		for ($j = 0; $j < $M; $j++) {
			if ($j) echo ' ';
			echo $A[$i][$j];
		}
		echo PHP_EOL;
	}
?>
```
###### STEP: 4
```php
<?php
	[$N, $M] = array_map("intval", explode(' ', fgets(STDIN)));
	$A = [];
	for ($i = 0; $i < $N; $i++) $A[] = array_map("intval", explode(' ', fgets(STDIN)));
	for ($i = 0; $i < $N; $i++) {
		for ($j = 0; $j < $M; $j++) {
			if ($j) echo ' ';
			echo $A[$i][$j];
		}
		echo PHP_EOL;
	}
?>
```
- - -
##### Perl
###### STEP: 1
```pl
my $N = 2;
my $M = 4;
my @A = ([1, 3, 5, 7], [8, 1, 3, 8]);
for (my $i = 0; $i < $N; $i++) {
	for (my $j = 0; $j < $M; $j++) {
		if ($j > 0) {
			print ' ';
		}
		print $A[$i][$j];
	}
	print $/;
}
```
###### STEP: 2
```pl
my $N = 5;
my $M = int(<STDIN>);
my @A;
for (my $i = 0; $i < $N; $i++) {
	push @A, [map { int($_) } split ' ', <STDIN>];
}
for (my $i = 0; $i < $N; $i++) {
	for (my $j = 0; $j < $M; $j++) {
		if ($j > 0) {
			print ' ';
		}
		print $A[$i][$j];
	}
	print $/;
}
```
###### STEP: 3
```pl
my $N = int(<STDIN>);
my $M = 5;
my @A;
for (my $i = 0; $i < $N; $i++) {
	push @A, [map { int($_) } split ' ', <STDIN>];
}
for (my $i = 0; $i < $N; $i++) {
	for (my $j = 0; $j < $M; $j++) {
		if ($j > 0) {
			print ' ';
		}
		print $A[$i][$j];
	}
	print $/;
}
```
###### STEP: 4
```pl
my ($N, $M) = map { int($_) } split ' ', <STDIN>;
my @A;
for (my $i = 0; $i < $N; $i++) {
	push @A, [map { int($_) } split ' ', <STDIN>];
}
for (my $i = 0; $i < $N; $i++) {
	for (my $j = 0; $j < $M; $j++) {
		if ($j > 0) {
			print ' ';
		}
		print $A[$i][$j];
	}
	print $/;
}
```
- - -
##### Python3
###### STEP: 1
```py
N = 2
M = 4
A = [ [ 1, 3, 5, 7 ], [ 8, 1, 3, 8 ] ]
for i in range(N):
	for j in range(M):
		if j:
			print(end=' ')
		print(A[i][j], end='')
	print()
```
###### STEP: 2
```py
N = 5
M = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
for i in range(N):
	for j in range(M):
		if j:
			print(end=' ')
		print(A[i][j], end='')
	print()
```
###### STEP: 3
```py
N = int(input())
M = 5
A = [list(map(int, input().split())) for _ in range(N)]
for i in range(N):
	for j in range(M):
		if j:
			print(end=' ')
		print(A[i][j], end='')
	print()
```
###### STEP: 4
```py
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
for i in range(N):
	for j in range(M):
		if j:
			print(end=' ')
		print(A[i][j], end='')
	print()
```
- - -
##### Ruby
###### STEP: 1
```rb
N = 2
M = 4
A = [ [ 1, 3, 5, 7 ], [ 8, 1, 3, 8 ] ]
N.times do |i|
	M.times do |j|
		if j > 0
			print ' '
		end
		print A[i][j]
	end
	puts
end
```
###### STEP: 2
```rb
N = 5
M = gets.to_i
A = N.times.map { gets.split.map(&:to_i) }
N.times do |i|
	M.times do |j|
		if j > 0
			print ' '
		end
		print A[i][j]
	end
	puts
end
```
###### STEP: 3
```rb
N = gets.to_i
M = 5
A = N.times.map { gets.split.map(&:to_i) }
N.times do |i|
	M.times do |j|
		if j > 0
			print ' '
		end
		print A[i][j]
	end
	puts
end
```
###### STEP: 4
```rb
N, M = gets.split.map(&:to_i)
A = N.times.map { gets.split.map(&:to_i) }
N.times do |i|
	M.times do |j|
		if j > 0
			print ' '
		end
		print A[i][j]
	end
	puts
end
```
- - -
##### Scala
###### STEP: 1
```scala
import scala.io.StdIn._

object Main extends App{
	val N = 2
	val M = 4
	val A = Array(Array(1, 3, 5, 7), Array(8, 1, 3, 8))
	for (i <- 0 until N) {
		for (j <- 0 until M) {
			if (j > 0) print(' ')
			print(A(i)(j))
		}
		println()
	}
}
```
###### STEP: 2
```scala
import scala.io.StdIn._

object Main extends App{
	val N = 5
	val M = readInt()
	val A = Array.fill(N) { readLine().split(' ').map { _.toInt } }
	for (i <- 0 until N) {
		for (j <- 0 until M) {
			if (j > 0) print(' ')
			print(A(i)(j))
		}
		println()
	}
}
```
###### STEP: 3
```scala
import scala.io.StdIn._

object Main extends App{
	val N = readInt()
	val M = 5
	val A = Array.fill(N) { readLine().split(' ').map { _.toInt } }
	for (i <- 0 until N) {
		for (j <- 0 until M) {
			if (j > 0) print(' ')
			print(A(i)(j))
		}
		println()
	}
}
```
###### STEP: 4
```scala
import scala.io.StdIn._

object Main extends App{
	val Array(n, m) = readLine().split(' ').map { _.toInt }
	val A = Array.fill(n) { readLine().split(' ').map { _.toInt } }
	for (i <- 0 until n) {
		for (j <- 0 until m) {
			if (j > 0) print(' ')
			print(A(i)(j))
		}
		println()
	}
}
```
- - -
##### Swift
###### STEP: 1
```swift
let N = 2
let M = 4
let A = [ [ 1, 3, 5, 7 ], [ 8, 1, 3, 8 ]]
for i in 0..<N {
	for j in 0..<M {
		if j > 0 {
			print(terminator: " ")
		}
		print(A[i][j], terminator: "")
	}
	print()
}
```
###### STEP: 2
```swift
let N = 5
let M = Int(readLine()!)!
var A: [[Int]] = []
for _ in 0..<N {
	A.append(readLine()!.split(separator: " ").compactMap { Int($0) })
}
for i in 0..<N {
	for j in 0..<M {
		if j > 0 {
			print(terminator: " ")
		}
		print(A[i][j], terminator: "")
	}
	print()
}
```
###### STEP: 3
```swift
let N = Int(readLine()!)!
let M = 5
var A: [[Int]] = []
for _ in 0..<N {
	A.append(readLine()!.split(separator: " ").compactMap { Int($0) })
}
for i in 0..<N {
	for j in 0..<M {
		if j > 0 {
			print(terminator: " ")
		}
		print(A[i][j], terminator: "")
	}
	print()
}
```
###### STEP: 4
```swift
let NM = readLine()!.split(separator: " ").compactMap { Int($0) }
let (N, M) = (NM[0], NM[1])
var A: [[Int]] = []
for _ in 0..<N {
	A.append(readLine()!.split(separator: " ").compactMap { Int($0) })
}
for i in 0..<N {
	for j in 0..<M {
		if j > 0 {
			print(terminator: " ")
		}
		print(A[i][j], terminator: "")
	}
	print()
}
```