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

paizaラーニングレベルアップ問題集の「二重ループメニュー」をやってみました。
- - -
##### 問題
###### 二次元配列の行ごとの和
https://paiza.jp/works/mondai/double_roop_problems/double_roop_problems__row_sum
###### さまざまな長さの配列の和
https://paiza.jp/works/mondai/double_roop_problems/double_roop_problems__various_row_sum
###### 階段の出力
https://paiza.jp/works/mondai/double_roop_problems/double_roop_problems__stairs
###### 積の最大
https://paiza.jp/works/mondai/double_roop_problems/double_roop_problems__multi_max
- - -
##### C
###### 二次元配列の行ごとの和
```c
#include <stdio.h>

int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
		int s = 0;
		for (int j = 0; j < k; j++) {
			int a;
			scanf("%d", &a);
			s += a;
		}
		printf("%d\n", s);
	}
	return 0;
}
```
###### さまざまな長さの配列の和
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int k;
		scanf("%d", &k);
		int s = 0;
		for (int j = 0; j < k; j++) {
			int a;
			scanf("%d", &a);
			s += a;
		}
		printf("%d\n", s);
	}
	return 0;
}
```
###### 階段の出力
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			printf("%d", j);
			if (j < i) putchar(' ');
		}
		puts("");
	}
	return 0;
}
```
###### 積の最大
```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[k];
	for (int j = 0; j < k; j++) scanf("%d", &B[j]);
	int max = -10000;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < k; j++) {
			int p = A[i] * B[j];
			if (p > max) max = p;
		}
	}
	printf("%d\n", max);
	return 0;
}
```
- - -
##### C++
###### 二次元配列の行ごとの和
```cpp
#include <iostream>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int s = 0;
		for (int j = 0; j < k; j++) {
			int a;
			cin >> a;
			s += a;
		}
		cout << s << endl;
	}
	return 0;
}
```
###### さまざまな長さの配列の和
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		int s = 0;
		for (int j = 0; j < k; j++) {
			int a;
			cin >> a;
			s += a;
		}
		cout << s << endl;
	}
	return 0;
}
```
###### 階段の出力
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			cout << j;
			if (j < i) cout << ' ';
		}
		cout << endl;
	}
	return 0;
}
```
###### 積の最大
```cpp
#include <iostream>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int A[n];
	for (int i = 0; i < n; i++) cin >> A[i];
	int B[k];
	for (int j = 0; j < k; j++) cin >> B[j];
	int m = -10000;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < k; j++) {
			int p = A[i] * B[j];
			if (p > m) m = p;
		}
	}
	cout << m << endl;
	return 0;
}
```
- - -
##### C#
###### 二次元配列の行ごとの和
```cs
using System;

class Program
{
	public static void Main()
	{
		int[] nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int n = nk[0], k = nk[1];
		for (int i = 0; i < n; i++) {
			int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
			int s = 0;
			for (int j = 0; j < k; j++) s += A[j];
			Console.WriteLine(s);
		}
	}
}
```
###### さまざまな長さの配列の和
```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 k = A[0];
			int s = 0;
			for (int j = 1; j <= k; j++) s += A[j];
			Console.WriteLine(s);
		}
	}
}
```
###### 階段の出力
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= i; j++) {
				Console.Write(j);
				if (j < i) Console.Write(' ');
			}
			Console.WriteLine();
		}
	}
}
```
###### 積の最大
```cs
using System;

class Program
{
	public static void Main()
	{
		int[] nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int n = nk[0], k = nk[1];
		int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int[] B = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int max = -10000;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < k; j++) {
				int p = A[i] * B[j];
				if (p > max) max = p;
			}
		}
		Console.WriteLine(max);
	}
}
```
- - -
##### Go
###### 二次元配列の行ごとの和
```go
package main
import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	for i := 0; i < n; i++ {
		s := 0
		for j := 0; j < k; j++ {
			var a int
			fmt.Scan(&a)
			s += a
		}
		fmt.Println(s)
	}
}
```
###### さまざまな長さの配列の和
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var k int
		fmt.Scan(&k)
		s := 0
		for j := 0; j < k; j++ {
			var a int
			fmt.Scan(&a)
			s += a
		}
		fmt.Println(s)
	}
}
```
###### 階段の出力
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		for j := 1; j <= i; j++ {
			fmt.Print(j)
			if j < i {
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}
```
###### 積の最大
```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, k)
	for j := 0; j < k; j++ {
		fmt.Scan(&B[j])
	}
	max := -10000
	for i := 0; i < n; i++ {
		for j := 0; j < k; j++ {
			p := A[i] * B[j]
			if p > max {
				max = p
			}
		}
	}
	fmt.Println(max)
}
```
- - -
##### Java
###### 二次元配列の行ごとの和
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int s = 0;
			for (int j = 0; j < k; j++) {
				int a = sc.nextInt();
				s += a;
			}
			System.out.println(s);
		}
		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 k = sc.nextInt();
			int s = 0;
			for (int j = 0; j < k; j++) {
				int a = sc.nextInt();
				s += a;
			}
			System.out.println(s);
		}
		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();
		sc.close();
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(j);
				if (j < i) System.out.print(' ');
			}
			System.out.println();
		}
	}
}
```
###### 積の最大
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.nextLine();
		int[] A = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		int[] B = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		sc.close();
		int max = -10000;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < k; j++) {
				int p = A[i] * B[j];
				if (p > max) max = p;
			}
		}
		System.out.println(max);
	}
}
```
- - -
##### JavaScript
###### 二次元配列の行ごとの和
```js
const [[n, k], ...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 = 0;
	for (var j = 0; j < k; j++) s += A[i][j];
	console.log(s);
}
```
###### さまざまな長さの配列の和
```js
const [[n], ...A] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map(s => s.split(' ').map(Number));
for (var i = 0; i < n; i++) {
	let k = A[i][0];
	let s = 0;
	for (var j = 1; j <= k; j++) s += A[i][j];
	console.log(s);
}
```
###### 階段の出力
```js
n = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
for (var i = 1; i <= n; i++) {
	let s = "";
	for (var j = 1; j <= i; j++) {
		s += j;
		if (j < i) s += " ";
	}
	console.log(s);
}
```
###### 積の最大
```js
const [[n, k], A, B] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map(s => s.split(' ').map(Number));
let max = -10000;
for (var i = 0; i < n; i++) {
	for (var j = 0; j < k; j++) {
		const p = A[i] * B[j];
		if (p > max) max = p;
	}
}
console.log(max);
```
- - -
##### Kotlin
###### 二次元配列の行ごとの和
```kotlin
fun main() {
	val (n, k) = readLine()!!.split(' ').map { it.toInt() }
	repeat(n) {
		val A = readLine()!!.split(' ').map { it.toInt() }
		var s = 0
		for (j in 0 until k) {
			s += A[j]
		}
		println(s)
	}
}
```
###### さまざまな長さの配列の和
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	repeat(n) {
		val A = readLine()!!.split(' ').map { it.toInt() }
		val k = A[0]
		var s = 0
		for (j in 1..k) {
			s += A[j]
		}
		println(s)
	}
}
```
###### 階段の出力
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	for (i in 1..n) {
		for (j in 1..i) {
			print(j)
			if (j < i) print(' ')
		}
		println()
	}
}
```
###### 積の最大
```kotlin
fun main() {
	val (n, k) = readLine()!!.split(' ').map { it.toInt() }
	val A = readLine()!!.split(' ').map { it.toInt() }
	val B = readLine()!!.split(' ').map { it.toInt() }
	var max = -10000
	for (i in 0 until n) {
		for (j in 0 until k) {
			val p = A[i] * B[j]
			if (p > max) max = p
		}
	}
	println(max)
}
```
- - -
##### PHP
###### 二次元配列の行ごとの和
```php
<?php
	[$n, $k] = array_map("intval", explode(' ', fgets(STDIN)));
	for ($i = 0; $i < $n; $i++) {
		$A = array_map("intval", explode(' ', fgets(STDIN)));
		$s = 0;
		for ($j = 0; $j < $k; $j++) $s += $A[$j];
		echo $s, PHP_EOL;
	}
?>
```
###### さまざまな長さの配列の和
```php
<?php
	$n = intval(fgets(STDIN));
	for ($i = 0; $i < $n; $i++) {
		$A = array_map("intval", explode(' ', fgets(STDIN)));
		$k = $A[0];
		$s = 0;
		for ($j = 1; $j <= $k; $j++) $s += $A[$j];
		echo $s, PHP_EOL;
	}
?>
```
###### 階段の出力
```php
<?php
	$n = intval(fgets(STDIN));
	for ($i = 1; $i <= $n; $i++) {
		for ($j = 1; $j <= $i; $j++) {
			echo $j;
			if ($j < $i) echo ' '; 
		}
		echo PHP_EOL;
	}
?>
```
###### 積の最大
```php
<?php
	[$n, $k] = array_map("intval", explode(' ', fgets(STDIN)));
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	$B = array_map("intval", explode(' ', fgets(STDIN)));
	$max = -10000;
	for ($i = 0; $i < $n; $i++) {
		for ($j = 0; $j < $k; $j++) {
			$p = $A[$i] * $B[$j];
			if ($p > $max) $max = $p;
		}
	}
	echo $max, PHP_EOL;
?>
```
- - -
##### Perl
###### 二次元配列の行ごとの和
```pl
my ($n, $k) = map { int($_) } split ' ', <STDIN>;
for (1..$n) {
	my @A = map { int($_) } split ' ', <STDIN>;
	my $s = 0;
	for (my $j = 0; $j < $k; $j++) {
		$s += $A[$j];
	}
	print "$s$/";
}
```
###### さまざまな長さの配列の和
```pl
my $n = int(<STDIN>);
for (1..$n) {
	my ($k, @A) = map { int($_) } split ' ', <STDIN>;
	my $s = 0;
	for (my $j = 0; $j < $k; $j++) {
		$s += $A[$j];
	}
	print "$s$/";
}
```
###### 階段の出力
```pl
my $n = int(<STDIN>);
for $i (1..$n) {
	for $j (1..$i) {
		print $j;
		if ($j < $i) {
			print ' ';
		}
	}
	print $/;
}
```
###### 積の最大
```pl
my ($n, $k) = map { int($_) } split ' ', <STDIN>;
my @A = map { int($_) } split ' ', <STDIN>;
my @B = map { int($_) } split ' ', <STDIN>;
my $max = -10000;
for (my $i = 0; $i < $n; $i++) {
	for (my $j = 0; $j < $k; $j++) {
		my $p = $A[$i] * $B[$j];
		if ($p > $max) {
			$max = $p;
		}
	}
}
print "$max$/";
```
- - -
##### Python3
###### 二次元配列の行ごとの和
```py
n, k = map(int, input().split())
for _ in range(n):
	A = list(map(int, input().split()))
	s = 0
	for j in range(k):
		s += A[j]
	print(s)
```
###### さまざまな長さの配列の和
```py
n = int(input())
for _ in range(n):
	k, *A = list(map(int, input().split()))
	s = 0
	for j in range(k):
		s += A[j]
	print(s)
```
###### 階段の出力
```py
n = int(input())
for i in range(1, n + 1):
	for j in range(1, i):
		print(j, end=' ')
	print(i)
```
###### 積の最大
```py
n, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
m = -10000
for i in range(n):
	for j in range(k):
		p = A[i] * B[j]
		if p > m:
			m = p
print(m)
```
- - -
##### Ruby
###### 二次元配列の行ごとの和
```rb
N, K = gets.split.map(&:to_i)
N.times do
	a = gets.split.map(&:to_i)
	s = 0
	K.times do |j|
		s += a[j]
	end
	p s
end
```
###### さまざまな長さの配列の和
```rb
N = gets.to_i
N.times do
	a = gets.split.map(&:to_i)
	k = a[0]
	s = 0
	(1..k).each do |j|
		s += a[j]
	end
	p s
end
```
###### 階段の出力
```rb
N = gets.to_i
(1..N).each do |i|
	(1..i).each do |j|
		print j
		if j < i
			print ' '
		end
	end
	puts
end
```
###### 積の最大
```rb
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
max = -10000
N.times do |i|
	K.times do |j|
		p = A[i] * B[j]
		if p > max
			max = p
		end
	end
end
p max
```
- - -
##### Scala
###### 二次元配列の行ごとの和
```scala
import scala.io.StdIn._

object Main extends App{
	val Array(n, k) = readLine().split(' ').map { _.toInt }
	for (i <- 0 until n) {
		val A = readLine().split(' ').map { _.toInt }
		var s = 0
		for (j <- 0 until k) s += A(j)
		println(s)
	}
}
```
###### さまざまな長さの配列の和
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	for (i <- 0 until n) {
		val A = readLine().split(' ').map { _.toInt }
		val k = A(0)
		var s = 0
		for (j <- 1 to k) s += A(j)
		println(s)
	}
}
```
###### 階段の出力
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	for (i <- 1 to n) {
		for (j <- 1 to i) {
			print(j)
			if (j < i) print(' ')
		}
		println()
	}
}
```
###### 積の最大
```scala
import scala.io.StdIn._

object Main extends App{
	val Array(n, k) = readLine().split(' ').map { _.toInt }
	val A = readLine().split(' ').map { _.toInt }
	val B = readLine().split(' ').map { _.toInt }
	var max = -10000
	for (i <- 0 until n) {
		for (j <- 0 until k) {
			val p = A(i) * B(j)
			if (p > max) max = p
		}
	}
	println(max)
}
```
- - -
##### Swift
###### 二次元配列の行ごとの和
```swift
let nk = readLine()!.split(separator: " ").compactMap { Int($0) }
let (n, k) = (nk[0], nk[1])
for _ in 0..<n {
	let A = readLine()!.split(separator: " ").compactMap { Int($0) }
	var s = 0
	for j in 0..<k {
		s += A[j]
	}
	print(s)
}
```
###### さまざまな長さの配列の和
```swift
let n = Int(readLine()!)!
for _ in 0..<n {
	let A = readLine()!.split(separator: " ").compactMap { Int($0) }
	let k = A[0]
	var s = 0
	for j in 1...k {
		s += A[j]
	}
	print(s)
}
```
###### 階段の出力
```swift
let n = Int(readLine()!)!
for i in 1...n {
	for j in 1..<i {
		print(j, terminator: " ")
	}
	print(i)
}
```
###### 積の最大
```swift
let nk = readLine()!.split(separator: " ").compactMap { Int($0) }
let (n, k) = (nk[0], nk[1])
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
let B = readLine()!.split(separator: " ").compactMap { Int($0) }
var m = -10000
for i in 0..<n {
	for j in 0..<k {
		let p = A[i] * B[j]
		if p > m {
			m = p
		}
	}
}
print(m)
```