paizaラーニングレベルアップ問題集の「配列メニュー」をやってみた。(4)

paizaラーニングレベルアップ問題集の「配列メニュー」をやってみました。
- - -
##### 問題
###### 要素数の出力
https://paiza.jp/works/mondai/array_primer/array_primer__2dmatrix_output_step1
###### 全要素の出力
https://paiza.jp/works/mondai/array_primer/array_primer__2dmatrix_output_step2
###### 行数の出力
https://paiza.jp/works/mondai/array_primer/array_primer__2dmatrix_output_step3
###### 列数の出力
https://paiza.jp/works/mondai/array_primer/array_primer__2dmatrix_output_step4
###### 各行の要素数の出力
https://paiza.jp/works/mondai/array_primer/array_primer__2dmatrix_output_step5
###### i行目j列目の出力
https://paiza.jp/works/mondai/array_primer/array_primer__2dmatrix_output_step6
- - -
##### C
###### 要素数の出力
```c
#include <stdio.h>

const int A[][6] = { { 1, 2, 3, 4, 5, 6 }, { 8, 1, 3, 3, 1, 8 } };

int main() {
	printf("%zu\n", sizeof(A) / sizeof(A[0][0]));
	return 0;
}
```
###### 全要素の出力
```c
#include <stdio.h>

const int A[][6] = { { 6, 5, 4, 3, 2, 1 }, { 3, 1, 8, 8, 1, 3 } };

int main() {
	for (size_t i = 0; i < sizeof(A) / sizeof(A[0]); i++) {
		for (size_t j = 0; j < sizeof(A[0]) / sizeof(A[0][0]); j++) {
			if (j) putchar(' ');
			printf("%d", A[i][j]);
		}
		puts("");
	}
	return 0;
}
```
###### 行数の出力
```c
#include <stdio.h>

const int A[][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 8, 1, 3 } };

int main() {
	printf("%zu\n", sizeof(A) / sizeof(A[0]));
	return 0;
}
```
###### 列数の出力
```c
#include <stdio.h>

const int A[][4] = { { 1, 2, 3, 4 }, { 6, 5, 4, 3 }, { 3, 1, 8, 1 } };

int main() {
	printf("%zu\n", sizeof(A[0]) / sizeof(A[0][0]));
	return 0;
}
```
###### 各行の要素数の出力
```c
#include <stdio.h>

const int A[][3] = { { 1 }, { 2, 3 }, { 4, 5, 6 } }; //{{1,0,0},{2,3,0},{4,5,6}}

int main() {
	size_t n = sizeof(A) / sizeof(A[0]);
	size_t m = sizeof(A[0]) / sizeof(A[0][0]);
	for (size_t i = 0; i < n; i++) {
		for (size_t j = 0; j <= m; j++) {
			if (j == m) {
				printf("%zu\n", j);
			} else if (!A[i][j]) { //番兵
				printf("%zu\n", j);
				break;
			}
		}
	}
	return 0;
}
```
###### i行目j列目の出力
```c
#include <stdio.h>

const int A[][3] = { { 1, 2, 3 }, { 8, 1, 3 }, { 10, 100, 1 } }; 

int main() {
	printf("%d\n", A[1][2]);
	return 0;
}
```
- - -
##### C++
###### 要素数の出力
```cpp
#include <iostream>
using namespace std;

const int A[][6] = { { 1, 2, 3, 4, 5, 6 }, { 8, 1, 3, 3, 1, 8 } };

int main() {
	cout << sizeof(A) / sizeof(A[0][0]) << endl;
	return 0;
}
```
###### 全要素の出力
```cpp
#include <iostream>
using namespace std;

const int A[][6] = { { 6, 5, 4, 3, 2, 1 }, { 3, 1, 8, 8, 1, 3 } };

int main() {
	for (size_t i = 0; i < sizeof(A) / sizeof(A[0]); i++) {
		for (size_t j = 0; j < sizeof(A[0]) / sizeof(A[0][0]); j++) {
			if (j) cout << ' ';
			cout << A[i][j];
		}
		cout << endl;
	}
	return 0;
}
```
###### 行数の出力
```cpp
#include <iostream>
using namespace std;

const int A[][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 8, 1, 3 } };

int main() {
	cout << sizeof(A) / sizeof(A[0]) << endl;
	return 0;
}
```
###### 列数の出力
```cpp
#include <iostream>
using namespace std;

const int A[][4] = { { 1, 2, 3, 4 }, { 6, 5, 4, 3 }, { 3, 1, 8, 1 } };

int main() {
	cout << sizeof(A[0]) / sizeof(A[0][0]) << endl;
	return 0;
}
```
###### 各行の要素数の出力
```cpp
#include <iostream>
#include <vector>
using namespace std;

const vector<vector<int>> A = { { 1 }, { 2, 3 }, { 4, 5, 6 } };

int main() {
	for (vector<int> a : A) cout << a.size() << endl;
	return 0;
}
```
###### 各行の要素数の出力
```cpp
#include <iostream>
using namespace std;

const int A[][3] = { { 1, 2, 3 }, { 8, 1, 3 }, { 10, 100, 1 } }; 

int main() {
	cout << A[1][2] << endl;
	return 0;
}
```
- - -
##### C#
###### 要素数の出力
```cs
using System;

class Program
{
	static readonly int[][] A = { new int[]{ 1, 2, 3, 4, 5, 6 }, new int[]{ 8, 1, 3, 3, 1, 8 } };
	
	public static void Main()
	{
		Console.WriteLine(A.Length * A[0].Length);
	}
}
```
###### 全要素の出力
```cs
using System;

class Program
{
	static readonly int[][] A = { new int[]{ 6, 5, 4, 3, 2, 1 }, new int[]{ 3, 1, 8, 8, 1, 3 } };
	
	public static void Main()
	{
		for (int i = 0; i < A.Length; i++) {
			for (int j = 0; j < A[i].Length; j++) {
				if (j > 0) Console.Write(' ');
				Console.Write(A[i][j]);
			}
			Console.WriteLine();
		}
	}
}
```
###### 行数の出力
```cs
using System;

class Program
{
	static readonly int[][] A = { new int[]{ 1, 2, 3 }, new int[]{ 4, 5, 6 },  new int[] { 8, 1, 3 }};
	
	public static void Main()
	{
		Console.WriteLine(A.Length);
	}
}
```
###### 列数の出力
```cs
using System;

class Program
{
	static readonly int[][] A = { new int[]{ 1, 2, 3, 4 }, new int[]{ 6, 5, 4, 3 }, new int[] { 3, 1, 8, 1 }};
	
	public static void Main()
	{
		Console.WriteLine(A[0].Length);
	}
}
```
###### 各行の要素数の出力
```cs
using System;

class Program
{
	static readonly int[][] A = { new int[]{ 1 }, new int[]{ 2, 3 }, new int[] { 4, 5, 6 }};
	
	public static void Main()
	{
		foreach (int[] a in A) Console.WriteLine(a.Length);
	}
}
```
###### i行目j列目の出力
```cs
using System;

class Program
{
	static readonly int[][] A = { new int[]{ 1, 2, 3 }, new int[]{ 8, 1, 3 }, new int[]{ 10, 100, 1 } };
	
	public static void Main()
	{
		Console.WriteLine(A[1][2]);
	}
}
```
- - -
##### Go
###### 要素数の出力
```go
package main
import "fmt"

var A = [][]int{ []int{ 1, 2, 3, 4, 5, 6 }, []int{ 8, 1, 3, 3, 1, 8 } }

func main() {
	fmt.Println(len(A) * len(A[0]))
}
```
###### 全要素の出力
```go
package main
import "fmt"

var A = [][]int{ []int{ 6, 5, 4, 3, 2, 1 }, []int{ 3, 1, 8, 8, 1, 3 } }

func main() {
	for i := 0; i < len(A); i++ {
		for j := 0; j < len(A[i]); j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(A[i][j])
		}
		fmt.Println()
	}
	
}
```
###### 行数の出力
```go
package main
import "fmt"

var A = [][]int{ []int{ 1, 2, 3 }, []int{ 4, 5, 6 }, []int{ 8, 1, 3 } }

func main() {
	fmt.Println(len(A))
}
```
###### 列数の出力
```go
package main
import "fmt"

var A = [][]int{ []int{ 1, 2, 3, 4 }, []int{ 6, 5, 4, 3 }, []int{ 3, 1, 8, 1 } }

func main() {
	fmt.Println(len(A[0]))
}
```
###### 各行の要素数の出力
```go
package main
import "fmt"

var A = [][]int{ []int{ 1 }, []int{ 2, 3 }, []int{ 4, 5, 6 } }

func main() {
	for _, a := range(A) {
		fmt.Println(len(a))
	}
}
```
###### i行目j列目の出力
```go
package main
import "fmt"

var A = [][]int{ []int{ 1, 2, 3 }, []int{ 8, 1, 3 }, []int{ 10, 100, 1 } }

func main() {
	fmt.Println(A[1][2])
}
```
- - -
##### Java
###### 要素数の出力
```java
public class Main {

	static final int[][] A = { { 1, 2, 3, 4, 5, 6 }, { 8, 1, 3, 3, 1, 8 } };
	
	public static void main(String[] args) {
		System.out.println(A.length * A[0].length);
	}
}
```
###### 全要素の出力
```java
public class Main {

	static final int[][] A = { { 6, 5, 4, 3, 2, 1 }, { 3, 1, 8, 8, 1, 3 } };
	
	public static void main(String[] args) {
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < A[i].length; j++) {
				if (j > 0) System.out.print(' ');
				System.out.print(A[i][j]);
			}
			System.out.println();
		}
	}
}
```
###### 行数の出力
```java
public class Main {

	static final int[][] A = { { 1, 2, 3 }, { 4, 5, 6 }, { 8, 1, 3 } };
	
	public static void main(String[] args) {
		System.out.println(A.length);
	}
}
```
###### 列数の出力
```java
public class Main {

	static final int[][] A = { { 1, 2, 3, 4 }, { 6, 5, 4, 3 }, { 3, 1, 8, 1 } };
	
	public static void main(String[] args) {
		System.out.println(A[0].length);
	}
}
```
###### 各行の要素数の出力
```java
public class Main {

	static final int[][] A = { { 1 }, { 2, 3 }, { 4, 5, 6 } };
	
	public static void main(String[] args) {
		for (int[] a : A) System.out.println(a.length);
	}
}
```
###### i行目j列目の出力
```java
public class Main {

	static final int[][] A = { { 1, 2, 3}, { 8, 1, 3 }, { 10, 100, 1 } };
	
	public static void main(String[] args) {
		System.out.println(A[1][2]);
	}
}
```
- - -
##### JavaScript
###### 要素数の出力
```js
const A = [ [ 1, 2, 3, 4, 5, 6 ], [ 8, 1, 3, 3, 1, 8 ] ];
console.log(A.length * A[0].length);
```
###### 全要素の出力
```js
const A = [ [ 6, 5, 4, 3, 2, 1 ], [ 3, 1, 8, 8, 1, 3 ] ];
for (var i = 0; i < A.length; i++) {
	s = "";
	for (var j = 0; j < A[i].length; j++) {
		if (j) s += ' ';
		s += A[i][j];
	}
	console.log(s);
}
```
###### 行数の出力
```js
const A = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 8, 1, 3 ] ];
console.log(A.length);
```
###### 列数の出力
```js
const A = [ [ 1, 2, 3, 4 ], [ 6, 5, 4, 3 ], [ 3, 1, 8, 1 ] ];
console.log(A[0].length);
```
###### 各行の要素数の出力
```js
const A = [ [ 1 ], [ 2, 3 ], [ 4, 5, 6 ] ];
A.forEach(a => console.log(a.length));
```
###### i行目j列目の出力
```js
const A = [ [ 1, 2, 3 ], [ 8, 1, 3 ], [ 10, 100, 1 ] ];
console.log(A[1][2]);
```
- - -
##### Kotlin
###### 要素数の出力
```kotlin
fun main() {
	val A = arrayOf(arrayOf(1, 2, 3, 4, 5, 6), arrayOf(8, 1, 3, 3, 1, 8))
	println(A.size * A[0].size)
}
```
###### 全要素の出力
```kotlin
fun main() {
	val A = arrayOf(arrayOf(6, 5, 4, 3, 2, 1), arrayOf(3, 1, 8, 8, 1, 3))
	for (i in 0 until A.size) {
		for (j in 0 until A[i].size) {
			if (j > 0) print(' ')
			print(A[i][j])
		}
		println()
	}
}
```
###### 行数の出力
```kotlin
fun main() {
	val A = arrayOf(arrayOf(1, 2, 3), arrayOf(4, 5, 6), arrayOf(8, 1, 3))
	println(A.size)
}
```
###### 列数の出力
```kotlin
fun main() {
	val A = arrayOf(arrayOf(1, 2, 3, 4), arrayOf(6, 5, 4, 3), arrayOf(3, 1, 8, 1))
	println(A[0].size)
}
```
###### 各行の要素数の出力
```kotlin
fun main() {
	val A = arrayOf(arrayOf(1), arrayOf(2, 3), arrayOf(4, 5, 6))
	for (a in A) println(a.size)
}
```
###### i行目j列目の出力
```kotlin
fun main() {
	val A = arrayOf(arrayOf(1, 2, 3), arrayOf(8, 1, 3), arrayOf(10, 100, 1))
	println(A[1][2])
}
```
- - -
##### PHP
###### 要素数の出力
```php
<?php
	$A = [ [ 1, 2, 3, 4, 5, 6 ], [ 8, 1, 3, 3, 1, 8 ] ];
	echo count($A) * count($A[0]), PHP_EOL;
?>
```
###### 全要素の出力
```php
<?php
	$A = [ [ 6, 5, 4, 3, 2, 1 ], [ 3, 1, 8, 8, 1, 3 ] ];
	for ($i = 0; $i < count($A); $i++) {
		for ($j = 0; $j < count($A[$i]); $j++) {
			if ($j) echo ' ';
			echo $A[$i][$j];
		}
		echo PHP_EOL;
	}
?>
```
###### 行数の出力
```php
<?php
	$A = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 8, 1, 3 ] ];
	echo count($A), PHP_EOL;
?>
```
###### 列数の出力
```php
<?php
	$A = [ [ 1, 2, 3, 4 ], [ 6, 5, 4, 3 ], [ 3, 1, 8, 1 ] ];
	echo count($A[0]), PHP_EOL;
?>
```
###### 各行の要素数の出力
```php
<?php
	$A = [ [ 1 ], [ 2, 3 ], [ 4, 5, 6 ] ];
	foreach ($A as $a) {
		echo count($a), PHP_EOL;
	}
?>
```
###### i行目j列目の出力
```php
<?php
	$A = [ [ 1, 2, 3 ], [ 8, 1, 3 ], [ 10, 100, 1 ] ];
	echo $A[1][2], PHP_EOL;
?>
```
- - -
##### Perl
###### 要素数の出力
```pl
my @A = ( [ 1, 2, 3, 4, 5, 6 ], [ 8, 1, 3, 3, 1, 8 ] );
print scalar(@A) * scalar(@{$A[0]}), $/;
```
###### 全要素の出力
```pl
my @A = ( [ 6, 5, 4, 3, 2, 1 ], [ 3, 1, 8, 8, 1, 3 ] );
for (my $i = 0; $i < scalar(@A); $i++) {
	for (my $j = 0; $j < scalar(@{$A[$i]}); $j++) {
		if ($j) {
			print ' ';
		}
		print $A[$i][$j];
	}
	print $/;
}
```
###### 行数の出力
```pl
my @A = ( [ 1, 2, 3 ], [ 4, 5, 6 ], [ 8, 1, 3 ] );
print scalar(@A), $/;
```
###### 列数の出力
```pl
my @A = ( [ 1, 2, 3, 4 ], [ 6, 5, 4, 3 ], [ 3, 1, 8, 1 ] );
print scalar(@{$A[0]}), $/;
```
###### 各行の要素数の出力
```pl
my @A = ( [ 1 ], [ 2, 3 ], [ 4, 5, 6 ] );
for (@A) {
	print scalar(@$_), $/;
}
```
###### i行目j列目の出力
```pl
my @A = ( [ 1, 2, 3 ], [ 8, 1, 3 ], [ 10, 100, 1 ] );
print $A[1][2], $/;
```
- - -
##### Python3
###### 要素数の出力
```py
A = [ [ 1, 2, 3, 4, 5, 6 ], [ 8, 1, 3, 3, 1, 8 ] ]
print(len(A) * len(A[0]))
```
###### 全要素の出力
```py
A = [ [ 6, 5, 4, 3, 2, 1 ], [ 3, 1, 8, 8, 1, 3 ] ]
for i in range(len(A)):
	for j in range(len(A[i])):
		if j:
			print(end=' ')
		print(A[i][j], end='')
	print()
```
###### 行数の出力
```py
A = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 8, 1, 3 ] ]
print(len(A))
```
###### 列数の出力
```py
A = [ [ 1, 2, 3, 4 ], [ 6, 5, 4, 3 ], [ 3, 1, 8, 1 ] ]
print(len(A[0]))
```
###### 各行の要素数の出力
```py
A = [ [ 1 ], [ 2, 3 ], [ 4, 5, 6 ] ]
for a in A:
	print(len(a))
```
###### i行目j列目の出力
```py
A = [ [ 1, 2, 3 ], [ 8, 1, 3 ], [ 10, 100, 1 ] ]
print(A[1][2])
```
- - -
##### Ruby
###### 要素数の出力
```rb
A = [ [ 1, 2, 3, 4, 5, 6 ], [ 8, 1, 3, 3, 1, 8 ] ]
p A.size * A[0].size
```
###### 全要素の出力
```rb
A = [ [ 6, 5, 4, 3, 2, 1 ], [ 3, 1, 8, 8, 1, 3 ] ]
A.size.times do |i|
	A[i].size.times do |j|
		if j > 0
			print ' '
		end
		print A[i][j]
	end
	puts
end
```
###### 行数の出力
```rb
A = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 8, 1, 3 ] ]
p A.size
```
###### 列数の出力
```rb
A = [ [ 1, 2, 3, 4 ], [ 6, 5, 4, 3 ], [ 3, 1, 8, 1 ] ]
p A[0].size
```
###### 各行の要素数の出力
```rb
A = [ [ 1 ], [ 2, 3 ], [ 4, 5, 6 ] ]
A.each do |a|
	p a.size
end
```
###### i行目j列目の出力
```rb
A = [ [ 1, 2, 3 ], [ 8, 1, 3 ], [ 10, 100, 1 ] ]
p A[1][2]
```
- - -
##### Scala
###### 要素数の出力
```scala
object Main extends App{
	val A = Array(Array(1, 2, 3, 4, 5, 6), Array(8, 1, 3, 3, 1, 8))
	println(A.size * A(0).size)
}
```
###### 全要素の出力
```scala
object Main extends App{
	val A = Array(Array(6, 5, 4, 3, 2, 1), Array(3, 1, 8, 8, 1, 3))
	for (i <- 0 until A.size) {
		for (j <- 0 until A(i).size) {
			if (j > 0) print(' ')
			print(A(i)(j))
		}
		println()
	}
}
```
###### 行数の出力
```scala
object Main extends App{
	val A = Array(Array(1, 2, 3), Array(4, 5, 6), Array(8, 1, 3))
	println(A.size)
}
```
###### 列数の出力
```scala
object Main extends App{
	val A = Array(Array(1, 2, 3, 4), Array(6, 5, 4, 3), Array(3, 1, 8, 1))
	println(A(0).size)
}
```
###### 各行の要素数の出力
```scala
object Main extends App{
	val A = Array(Array(1), Array(2, 3), Array(4, 5, 6))
	for (a <- A) println(a.size)
}
```
###### i行目j列目の出力
```scala
object Main extends App{
	val A = Array(Array(1, 2, 3), Array(8, 1, 3), Array(10, 100, 1))
	println(A(1)(2))
}
```
- - -
##### Swift
###### 要素数の出力
```swift
let A = [ [ 1, 2, 3, 4, 5, 6 ], [ 8, 1, 3, 3, 1, 8 ] ]
print(A.count * A[0].count)
```
###### 全要素の出力
```swift
let A = [ [ 6, 5, 4, 3, 2, 1 ], [ 3, 1, 8, 8, 1, 3 ] ]
for i in 0..<A.count {
	for j in 0..<A[i].count {
		if j > 0 {
			print(terminator: " ")
		}
		print(A[i][j], terminator: "")
	}
	print()
}
```
###### 行数の出力
```swift
let A = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 8, 1, 3 ] ]
print(A.count)
```
###### 列数の出力
```swift
let A = [ [ 1, 2, 3, 4 ], [ 6, 5, 4, 3 ], [ 3, 1, 8, 1 ] ]
print(A[0].count)
```
###### 各行の要素数の出力
```swift
let A = [ [ 1 ], [ 2, 3 ], [ 4, 5, 6 ] ]
for a in A {
	print(a.count)
}
```
###### i行目j列目の出力
```swift
let A = [ [ 1, 2, 3 ], [ 8, 1, 3 ], [ 10, 100, 1 ] ]
print(A[1][2])
```