paizaラーニングレベルアップ問題集の【N行M列のデータの入力】をやってみた。

paizaラーニングレベルアップ問題集の【N行M列のデータの入力】をやってみました。
- - -
##### 問題
###### 3行3列の整数の入力
https://paiza.jp/works/mondai/stdin_primer/stdin_primer__matrix_data_step1
###### N行3列の整数の入力
https://paiza.jp/works/mondai/stdin_primer/stdin_primer__matrix_data_step2
###### 3行M列の整数の入力
https://paiza.jp/works/mondai/stdin_primer/stdin_primer__matrix_data_step3
###### N行M列の整数の入力
https://paiza.jp/works/mondai/stdin_primer/stdin_primer__matrix_data_step4
###### 行ごとに要素数の異なる整数列の入力
https://paiza.jp/works/mondai/stdin_primer/stdin_primer__matrix_data_boss
- - -
##### C
###### 3行3列の整数の入力
```c
#include <stdio.h>

const int N = 3;
const int M = 3;

int main() {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (j) putchar(' ');
			int a;
			scanf("%d", &a);
			printf("%d", a);
		}
		puts("");
	}
	return 0;
}
```
###### N行3列の整数の入力
```c
#include <stdio.h>

const int M = 3;

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < M; j++) {
			if (j) putchar(' ');
			int a;
			scanf("%d", &a);
			printf("%d", a);
		}
		puts("");
	}
	return 0;
}
```
###### 3行M列の整数の入力
```c
#include <stdio.h>

const int N = 3;

int main() {
	int m;
	scanf("%d", &m);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < m; j++) {
			if (j) putchar(' ');
			int a;
			scanf("%d", &a);
			printf("%d", a);
		}
		puts("");
	}
	return 0;
}
```
###### N行M列の整数の入力
```c
#include <stdio.h>

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (j) putchar(' ');
			int a;
			scanf("%d", &a);
			printf("%d", a);
		}
		puts("");
	}
	return 0;
}
```
###### 行ごとに要素数の異なる整数列の入力
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int m;
		scanf("%d", &m);
		for (int j = 0; j < m; j++) {
			if (j) putchar(' ');
			int a;
			scanf("%d", &a);
			printf("%d", a);
		}
		puts("");
	}
	return 0;
}
```
- - -
##### C++
###### 3行3列の整数の入力
```cpp
#include <iostream>
using namespace std;

const int N = 3;
const int M = 3;

int main() {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (j) cout << ' ';
			int a;
			cin >> a;
			cout << a;
		}
		cout << endl;
	}
	return 0;
}
```
###### N行3列の整数の入力
```cpp
#include <iostream>
using namespace std;

const int M = 3;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < M; j++) {
			if (j) cout << ' ';
			int a;
			cin >> a;
			cout << a;
		}
		cout << endl;
	}
	return 0;
}
```
###### 3行M列の整数の入力
```cpp
#include <iostream>
using namespace std;

const int N = 3;

int main() {
	int m;
	cin >> m;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < m; j++) {
			if (j) cout << ' ';
			int a;
			cin >> a;
			cout << a;
		}
		cout << endl;
	}
	return 0;
}
```
###### N行M列の整数の入力
```cpp
#include <iostream>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (j) cout << ' ';
			int a;
			cin >> a;
			cout << a;
		}
		cout << endl;
	}
	return 0;
}
```
###### 行ごとに要素数の異なる整数列の入力
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int m;
		cin >> m;
		for (int j = 0; j < m; j++) {
			if (j) cout << ' ';
			int a;
			cin >> a;
			cout << a;
		}
		cout << endl;
	}
	return 0;
}
```
- - -
##### C#
###### 3行3列の整数の入力
```cs
using System;

class Program
{
	private const int N = 3;
	private const int M = 3;
	
	public static void Main()
	{
		for (int i = 0; i < N; i++) {
			int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
			for (int j = 0; j < M; j++) {
				if (j > 0) Console.Write(' ');
				Console.Write(A[j]);
			}
			Console.WriteLine();
		}
	}
}
```
###### N行3列の整数の入力
```cs
using System;

class Program
{
	private const int M = 3;
	
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		for (int i = 0; i < n; i++) {
			int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
			for (int j = 0; j < M; j++) {
				if (j > 0) Console.Write(' ');
				Console.Write(A[j]);
			}
			Console.WriteLine();
		}
	}
}
```
###### 3行M列の整数の入力
```cs
using System;

class Program
{
	private const int N = 3;
	
	public static void Main()
	{
		int m = int.Parse(Console.ReadLine());
		for (int i = 0; i < N; i++) {
			int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
			for (int j = 0; j < m; j++) {
				if (j > 0) Console.Write(' ');
				Console.Write(A[j]);
			}
			Console.WriteLine();
		}
	}
}
```
###### N行M列の整数の入力
```cs
using System;

class Program
{
	
	public static void Main()
	{
		int[] nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int n = nm[0];
		int m = nm[1];
		for (int i = 0; i < n; i++) {
			int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
			for (int j = 0; j < m; j++) {
				if (j > 0) Console.Write(' ');
				Console.Write(A[j]);
			}
			Console.WriteLine();
		}
	}
}
```
###### 行ごとに要素数の異なる整数列の入力
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		for (int i = 0; i < n; i++) {
			int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
			int m = A[0];
			for (int j = 1; j <= m; j++) {
				Console.Write(A[j]);
				if (j < m) Console.Write(' ');
			}
			Console.WriteLine();
		}
	}
}
```
- - -
##### Go
###### 3行3列の整数の入力
```go
package main
import "fmt"

const N = 3
const M = 3

func main() {
	for i := 0; i < N; i++ {
		for j := 0; j < M; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			var a int
			fmt.Scan(&a)
			fmt.Print(a)
		}
		fmt.Println()
	}
}
```
###### N行3列の整数の入力
```go
package main
import "fmt"

const M = 3

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		for j := 0; j < M; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			var a int
			fmt.Scan(&a)
			fmt.Print(a)
		}
		fmt.Println()
	}
}
```
###### 3行M列の整数の入力
```go
package main
import "fmt"

const N = 3

func main() {
	var m int
	fmt.Scan(&m)
	for i := 0; i < N; i++ {
		for j := 0; j < m; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			var a int
			fmt.Scan(&a)
			fmt.Print(a)
		}
		fmt.Println()
	}
}
```
###### N行M列の整数の入力
```go
package main
import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			var a int
			fmt.Scan(&a)
			fmt.Print(a)
		}
		fmt.Println()
	}
}
```
###### 行ごとに要素数の異なる整数列の入力
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var m int
		fmt.Scan(&m)
		for j := 0; j < m; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			var a int
			fmt.Scan(&a)
			fmt.Print(a)
		}
		fmt.Println()
	}
}
```
- - -
##### Java
###### 3行3列の整数の入力
```java
import java.util.*;

public class Main {

	private static final int N = 3;
	private static final int M = 3;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				if (j > 0) System.out.print(' ');
				System.out.print(sc.nextInt());
			}
			System.out.println();
		}
		sc.close();
	}
}
```
###### N行3列の整数の入力
```java
import java.util.*;

public class Main {

	private static final int M = 3;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < M; j++) {
				if (j > 0) System.out.print(' ');
				System.out.print(sc.nextInt());
			}
			System.out.println();
		}
		sc.close();
	}
}
```
###### 3行M列の整数の入力
```java
import java.util.*;

public class Main {

	private static final int N = 3;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < m; j++) {
				if (j > 0) System.out.print(' ');
				System.out.print(sc.nextInt());
			}
			System.out.println();
		}
		sc.close();
	}
}
```
###### N行M列の整数の入力
```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();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (j > 0) System.out.print(' ');
				System.out.print(sc.nextInt());
			}
			System.out.println();
		}
		sc.close();
	}
}
```
###### 行ごとに要素数の異なる整数列の入力
```java
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int m = sc.nextInt();
			for (int j = 0; j < m; j++) {
				if (j > 0) System.out.print(' ');
				System.out.print(sc.nextInt());
			}
			System.out.println();
		}
		sc.close();
	}
}
```
- - -
##### JavaScript
###### 3行3列の整数の入力
```js
const [N, M] = [3, 3];
const A = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map((s) => s.split(' ').map(Number));
for (var i = 0; i < N; i++)
	console.log(A[i].join(' '));
```
###### N行3列の整数の入力
```js
const M = 3;
const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n');
const N = Number(lines[0]);
for (var i = 1; i <= N; i++) {
	let A = lines[i].split(' ').map(Number);
	console.log(A.join(' '));
}
```
###### 3行M列の整数の入力
```js
const N = 3;
const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n');
const M = Number(lines[0]);
for (var i = 1; i <= N; i++) {
	let A = lines[i].split(' ').map(Number);
	console.log(A.join(' '));
}
```
###### N行M列の整数の入力
```js
const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n');
const [N, M] = lines[0].split(' ').map(Number);
for (var i = 1; i <= N; i++) {
	let A = lines[i].split(' ').map(Number);
	console.log(A.join(' '));
}
```
###### 行ごとに要素数の異なる整数列の入力
```js
const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n');
const N = Number(lines[0]);
for (var i = 1; i <= N; i++) {
	let [M, ...A] = lines[i].split(' ').map(Number);
	console.log(A.join(' '));
}
```
- - -
##### Kotlin
###### 3行3列の整数の入力
```kotlin
val N = 3
val M = 3

fun main() {
	for (i in 0 until N) {
		val A = readLine()!!.split(' ').map { it.toInt() }
		for (j in 0 until M) {
			if (j > 0) print(' ')
			print(A[j])
		}
		println()
	}
}
```
###### N行3列の整数の入力
```kotlin
val M = 3

fun main() {
	val n = readLine()!!.toInt()
	for (i in 0 until n) {
		val A = readLine()!!.split(' ').map { it.toInt() }
		for (j in 0 until M) {
			if (j > 0) print(' ')
			print(A[j])
		}
		println()
	}
}
```
###### 3行M列の整数の入力
```kotlin
val N = 3

fun main() {
	val m = readLine()!!.toInt()
	for (i in 0 until N) {
		val A = readLine()!!.split(' ').map { it.toInt() }
		for (j in 0 until m) {
			if (j > 0) print(' ')
			print(A[j])
		}
		println()
	}
}
```
###### N行M列の整数の入力
```kotlin
fun main() {
	val (n, m) = readLine()!!.split(' ').map { it.toInt() }
	for (i in 0 until n) {
		val A = readLine()!!.split(' ').map { it.toInt() }
		for (j in 0 until m) {
			if (j > 0) print(' ')
			print(A[j])
		}
		println()
	}
}
```
###### 行ごとに要素数の異なる整数列の入力
```kotlin
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	val n = sc.nextInt()
	for (i in 0 until n) {
		val m = sc.nextInt()
		for (j in 0 until m) {
			if (j > 0) print(' ')
			val a = sc.nextInt()
			print(a)
		}
		println()
	}
	sc.close()
}
```
- - -
##### PHP
###### 3行3列の整数の入力
```php
<?php
	$N = 3;
	$M = 3;
	for ($i = 0; $i < $N; $i++) {
		$A = array_map("intval", explode(' ', trim(fgets(STDIN))));
		for ($j = 0; $j < $M; $j++) {
			if ($j) echo ' ';
			echo $A[$j];
		}
		echo PHP_EOL;
	}
?>
```
###### N行3列の整数の入力
```php
<?php
	$N = intval(fgets(STDIN));
	$M = 3;
	for ($i = 0; $i < $N; $i++) {
		$A = array_map("intval", explode(' ', trim(fgets(STDIN))));
		for ($j = 0; $j < $M; $j++) {
			if ($j) echo ' ';
			echo $A[$j];
		}
		echo PHP_EOL;
	}
?>
```
###### 3行M列の整数の入力
```php
<?php
	$N = 3;
	$M = intval(fgets(STDIN));
	for ($i = 0; $i < $N; $i++) {
		$A = array_map("intval", explode(' ', trim(fgets(STDIN))));
		for ($j = 0; $j < $M; $j++) {
			if ($j) echo ' ';
			echo $A[$j];
		}
		echo PHP_EOL;
	}
?>
```
###### N行M列の整数の入力
```php
<?php
	[$N, $M] = array_map("intval", explode(' ', trim(fgets(STDIN))));
	for ($i = 0; $i < $N; $i++) {
		$A = array_map("intval", explode(' ', trim(fgets(STDIN))));
		for ($j = 0; $j < $M; $j++) {
			if ($j) echo ' ';
			echo $A[$j];
		}
		echo PHP_EOL;
	}
?>
```
###### 行ごとに要素数の異なる整数列の入力
```php
<?php
	$N = intval(fgets(STDIN));
	for ($i = 0; $i < $N; $i++) {
		$A = array_map("intval", explode(' ', trim(fgets(STDIN))));
		$M = $A[0];
		for ($j = 1; $j <= $M; $j++) {
			echo $A[$j];
			if ($j < $M) echo ' ';
		}
		echo PHP_EOL;
	}
?>
```
- - -
##### Perl
###### 3行3列の整数の入力
```pl
my $N = 3;
my $M = 3;
for (my $i = 0; $i < $N; $i++) {
	my @A = map { int($_) } split ' ', <STDIN>;
	for (my $j = 0; $j < $M; $j++) {
		if ($j) {
			print ' ';
		}
		print $A[$j];
	}
	print $/;
}
```
###### N行3列の整数の入力
```pl
my $N = int(<STDIN>);
my $M = 3;
for (my $i = 0; $i < $N; $i++) {
	my @A = map { int($_) } split ' ', <STDIN>;
	for (my $j = 0; $j < $M; $j++) {
		if ($j) {
			print ' ';
		}
		print $A[$j];
	}
	print $/;
}
```
###### 3行M列の整数の入力
```pl
my $N = 3;
my $M = int(<STDIN>);
for (my $i = 0; $i < $N; $i++) {
	my @A = map { int($_) } split ' ', <STDIN>;
	for (my $j = 0; $j < $M; $j++) {
		if ($j) {
			print ' ';
		}
		print $A[$j];
	}
	print $/;
}
```
###### N行M列の整数の入力
```pl
my ($N, $M) = map { int($_) } split ' ', <STDIN>;
for (my $i = 0; $i < $N; $i++) {
	my @A = map { int($_) } split ' ', <STDIN>;
	for (my $j = 0; $j < $M; $j++) {
		if ($j) {
			print ' ';
		}
		print $A[$j];
	}
	print $/;
}
```
###### 行ごとに要素数の異なる整数列の入力
```pl
my $N = int(<STDIN>);
for (my $i = 0; $i < $N; $i++) {
	my ($m, @A) = map { int($_) } split ' ', <STDIN>;
	for (my $j = 0; $j < $m; $j++) {
		if ($j > 0) {
			print ' ';
		}
		print $A[$j];
	}
	print $/;
}
```
- - -
##### Python3
###### 3行3列の整数の入力
```py
N = M = 3
for _ in range(N):
	A = list(map(int, input().split()))
	print(*A)
```
###### N行3列の整数の入力
```py
N = int(input())
M = 3
for _ in range(N):
	A = list(map(int, input().split()))
	print(*A)
```
###### 3行M列の整数の入力
```py
N = 3
M = int(input())
for _ in range(N):
	A = list(map(int, input().split()))
	print(*A)
```
###### N行M列の整数の入力
```py
N, M = map(int, input().split())
for _ in range(N):
	A = list(map(int, input().split()))
	print(*A)
```
###### 行ごとに要素数の異なる整数列の入力
```py
N = int(input())
for _ in range(N):
	M, *A = map(int, input().split())
	print(*A)
```
- - -
##### Ruby
###### 3行3列の整数の入力
```rb
N = M = 3
N.times do
	a = gets.split.map(&:to_i)
	M.times do |j|
		if j > 0
			print ' '
		end
		print a[j]
	end
	puts
end
```
###### N行3列の整数の入力
```rb
N = gets.to_i
M = 3
N.times do
	a = gets.split.map(&:to_i)
	M.times do |j|
		if j > 0
			print ' '
		end
		print a[j]
	end
	puts
end
```
###### 3行M列の整数の入力
```rb
N = 3
M = gets.to_i
N.times do
	a = gets.split.map(&:to_i)
	M.times do |j|
		if j > 0
			print ' '
		end
		print a[j]
	end
	puts
end
```
###### N行M列の整数の入力
```rb
N, M = gets.split.map(&:to_i)
N.times do
	a = gets.split.map(&:to_i)
	M.times do |j|
		if j > 0
			print ' '
		end
		print a[j]
	end
	puts
end
```
###### 行ごとに要素数の異なる整数列の入力
```rb
N = gets.to_i
N.times do
	m, *a = gets.split.map(&:to_i)
	m.times do |j|
		if j > 0
			print ' '
		end
		print a[j]
	end
	puts
end
```
- - -
##### Scala
###### 3行3列の整数の入力
```scala
import scala.io.StdIn._

object Main extends App{
	val N = 3
	val M = 3
	for (i <- 0 until N) {
		val A = readLine().split(' ').map(_.toInt)
		for (j <- 0 until M) {
			if (j > 0) print(' ')
			print(A(j))
		}
		println()
	}
}
```
###### N行3列の整数の入力
```scala
import scala.io.StdIn._

object Main extends App{
	val N = readInt()
	val M = 3
	for (i <- 0 until N) {
		val A = readLine().split(' ').map(_.toInt)
		for (j <- 0 until M) {
			if (j > 0) print(' ')
			print(A(j))
		}
		println()
	}
}
```
###### 3行M列の整数の入力
```scala
import scala.io.StdIn._

object Main extends App{
	val N = 3
	val M = readInt()
	for (i <- 0 until N) {
		val A = readLine().split(' ').map(_.toInt)
		for (j <- 0 until M) {
			if (j > 0) print(' ')
			print(A(j))
		}
		println()
	}
}
```
###### N行M列の整数の入力
```scala
import scala.io.StdIn._

object Main extends App{
	val Array(n, m) = readLine().split(' ').map(_.toInt)
	for (i <- 0 until n) {
		val A = readLine().split(' ').map(_.toInt)
		for (j <- 0 until m) {
			if (j > 0) print(' ')
			print(A(j))
		}
		println()
	}
}
```
###### 行ごとに要素数の異なる整数列の入力
```scala
import java.util._

object Main extends App{
	val sc = new Scanner(System.in)
	val n = sc.nextInt()
	for (i <- 0 until n) {
		val m = sc.nextInt()
		for (j <- 0 until m) {
			if (j > 0) print(' ')
			print(sc.nextInt())
		}
		println()
	}
	sc.close()
}
```
- - -
##### Swift
###### 3行3列の整数の入力
```swift
let N = 3
let M = 3
for _ in 0..<N {
	let A = readLine()!.split(separator: " ").compactMap { Int($0) }
	print(A.map{ String($0) }.joined(separator: " "))
}
```
###### N行3列の整数の入力
```swift
let N = Int(readLine()!)!
let M = 3
for _ in 0..<N {
	let A = readLine()!.split(separator: " ").compactMap { Int($0) }
	print(A.map{ String($0) }.joined(separator: " "))
}
```
###### 3行M列の整数の入力
```swift
let N = 3
let M = Int(readLine()!)!
for _ in 0..<N {
	let A = readLine()!.split(separator: " ").compactMap { Int($0) }
	print(A.map{ String($0) }.joined(separator: " "))
}
```
###### N行M列の整数の入力
```swift
let nm = readLine()!.split(separator: " ").compactMap { Int($0) }
let n = nm[0]
let m = nm[1]
for _ in 0..<n {
	let A = readLine()!.split(separator: " ").compactMap { Int($0) }
	print(A.map{ String($0) }.joined(separator: " "))
}
```
###### 行ごとに要素数の異なる整数列の入力
```swift
let N = Int(readLine()!)!
for _ in 0..<N {
	let A = readLine()!.split(separator: " ").compactMap { Int($0) }
	print(A[1...].map{ String($0) }.joined(separator: " "))
}
```