paizaラーニングレベルアップ問題集の【ループメニュー】をやってみた。(2)

paizaラーニングレベルアップ問題集の【ループメニュー】をやってみました。
- - -
##### 問題
###### 数列の和
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_sum
###### 数列のA番目からB番目までの和
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_partsum
###### 数列の値を全部*2して出力
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_multi
###### 数列同士の引き算
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_sub
- - -
今回は`sum`関数等の使用は控えさせて頂きます。
- - -
##### C
###### 数列の和
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	int A[n];
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	int s = 0;
	for (int i = 0; i < n; i++) s += A[i];
	printf("%d\n", s);
	return 0;
}
```
###### 数列のA番目からB番目までの和
```c
#include <stdio.h>

int main() {
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	a -= 1;
	int A[n];
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	int s = 0;
	for (int i = a; i < b; i++) s += A[i];
	printf("%d\n", s);
	return 0;
}
```
###### 数列の値を全部*2して出力
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	int A[n];
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	for (int i = 0; i < n; i++) printf("%d\n", A[i] * 2);
	return 0;
}
```
###### 数列同士の引き算
```c
#include <stdio.h>

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

int main() {
	int n;
	cin >> n;
	int A[n];
	for (int i = 0; i < n; i++) cin >> A[i];
	int s = 0;
	for (int i = 0; i < n; i++) s += A[i];
	cout << s << endl;
	return 0;
}
```
###### 数列のA番目からB番目までの和
```cpp
#include <iostream>
using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	a -= 1;
	int A[n];
	for (int i = 0; i < n; i++) cin >> A[i];
	int s = 0;
	for (int i = a; i < b; i++) s += A[i];
	cout << s << endl;
	return 0;
}
```
###### 数列の値を全部*2して出力
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	int A[n];
	for (int i = 0; i < n; i++) cin >> A[i];
	for (int i = 0; i < n; i++) cout << A[i] * 2 << endl;
	return 0;
}
```
###### 数列同士の引き算
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	int A[n];
	for (int i = 0; i < n; i++) cin >> A[i];
	int B[n];
	for (int i = 0; i < n; i++) cin >> B[i];
	for (int i = 0; i < n; i++) cout << A[i] - B[i] << endl;
	return 0;
}
```
- - -
##### C#
###### 数列の和
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int s = 0;
		for (int i = 0; i < n; i++) s += A[i];
		Console.WriteLine(s);
	}
}
```
###### 数列のA番目からB番目までの和
```cs
using System;

class Program
{
	public static void Main()
	{
		int[] nab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int n = nab[0], a = nab[1] - 1, b = nab[2];
		int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int s = 0;
		for (int i = a; i < b; i++) s += A[i];
		Console.WriteLine(s);
	}
}
```
###### 数列の値を全部*2して出力
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		for (int i = 0; i < n; i++) Console.WriteLine(A[i] * 2);
	}
}
```
###### 数列同士の引き算
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int[] B = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		for (int i = 0; i < n; i++) Console.WriteLine(A[i] - B[i]);
	}
}
```
- - -
##### Go
###### 数列の和
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	A := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&A[i])
	}
	s := 0
	for i := 0; i < n; i++ {
		s += A[i]
	}
	fmt.Println(s)
}
```
###### 数列のA番目からB番目までの和
```go
package main
import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	fmt.Println(s)
}
```
###### 数列の値を全部*2して出力
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	A := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&A[i])
	}
	for i := 0; i < n; i++ {
		fmt.Println(A[i] * 2)
	}
}
```
###### 数列同士の引き算
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	A := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&A[i])
	}
	B := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&B[i])
	}
	for i := 0; i < n; i++ {
		fmt.Println(A[i] - B[i])
	}
}
```
- - -
##### 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[] A = new int[n];
		for (int i = 0; i < n; i++) A[i] = sc.nextInt();
		sc.close();
		int s = 0;
		for (int i = 0; i < n; i++) s += A[i];
		System.out.println(s);
	}
}
```
###### 数列のA番目からB番目までの和
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt() - 1;
		int b = sc.nextInt();
		int[] A = new int[n];
		for (int i = 0; i < n; i++) A[i] = sc.nextInt();
		sc.close();
		int s = 0;
		for (int i = a; i < b; i++) s += A[i];
		System.out.println(s);
	}
}
```
###### 数列の値を全部*2して出力
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] A = new int[n];
		for (int i = 0; i < n; i++) A[i] = sc.nextInt();
		sc.close();
		for (int i = 0; i < n; i++) System.out.println(A[i] * 2);
	}
}
```
###### 数列同士の引き算
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] A = new int[n];
		for (int i = 0; i < n; i++) A[i] = sc.nextInt();
		int[] B = new int[n];
		for (int i = 0; i < n; i++) B[i] = sc.nextInt();
		sc.close();
		for (int i = 0; i < n; i++) System.out.println(A[i] - B[i]);
	}
}
```
- - -
##### JavaScript
###### 数列の和
```js
const [N, A] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map((s, i) => i ? s.split(' ').map(Number) : Number(s));
let s = 0;
for (var i = 0; i < N; i++) s += A[i];
console.log(s);
```
###### 数列のA番目からB番目までの和
```js
const [[N, a, b], A] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map(s => s.split(' ').map(Number));
let s = 0;
for (var i = a - 1; i < b; i++) s += A[i];
console.log(s);
```
###### 数列の値を全部*2して出力
```js
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++) console.log(A[i] * 2);
```
###### 数列同士の引き算
```js
const [N, A, B] = 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++) console.log(A[i] - B[i]);
```
- - -
##### Kotlin
###### 数列の和
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	val A = readLine()!!.split(' ').map { it.toInt() }
	var s = 0
	for (i in 0 until n) s += A[i]
	println(s)
}
```
###### 数列のA番目からB番目までの和
```kotlin
fun main() {
	val (n, a, b) = readLine()!!.split(' ').map { it.toInt() }
	val A = readLine()!!.split(' ').map { it.toInt() }
	var s = 0
	for (i in a-1 until b) s += A[i]
	println(s)
}
```
###### 数列の値を全部*2して出力
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	val A = readLine()!!.split(' ').map { it.toInt() }
	for (i in 0 until n) println(A[i] * 2)
}
```
###### 数列同士の引き算
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	val A = readLine()!!.split(' ').map { it.toInt() }
	val B = readLine()!!.split(' ').map { it.toInt() }
	for (i in 0 until n) println(A[i] - B[i])
}
```
- - -
##### PHP
###### 数列の和
```php
<?php
	$n = intval(fgets(STDIN));
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	$s = 0;
	for ($i = 0; $i < $n; $i++) $s += $A[$i];
	echo $s, PHP_EOL;
?>
```
###### 数列のA番目からB番目までの和
```php
<?php
	[$n, $a, $b] = array_map("intval", explode(' ', fgets(STDIN)));
	$a -= 1;
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	$s = 0;
	for ($i = $a; $i < $b; $i++) $s += $A[$i];
	echo $s, PHP_EOL;
?>
```
###### 数列の値を全部*2して出力
```php
<?php
	$n = intval(fgets(STDIN));
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	for ($i = 0; $i < $n; $i++) echo $A[$i] * 2, PHP_EOL;
?>
```
###### 数列同士の引き算
```php
<?php
	$n = intval(fgets(STDIN));
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	$B = array_map("intval", explode(' ', fgets(STDIN)));
	for ($i = 0; $i < $n; $i++) echo $A[$i] - $B[$i], PHP_EOL;
?>
```
- - -
##### Perl
###### 数列の和
```pl
my $n = int(<STDIN>);
my @A = map { int($_) } split ' ', <STDIN>;
my $s = 0;
for (my $i = 0; $i < $n; $i++) {
	$s += $A[$i];
}
print "$s$/";
```
###### 数列のA番目からB番目までの和
```pl
my ($n, $a, $b) = map { int($_) } split ' ', <STDIN>;
$a -= 1;
my @A = map { int($_) } split ' ', <STDIN>;
my $s = 0;
for (my $i = $a; $i < $b; $i++) {
	$s += $A[$i];
}
print "$s$/";
```
###### 数列の値を全部*2して出力
```pl
my $n = int(<STDIN>);
my @A = map { int($_) } split ' ', <STDIN>;
for (my $i = 0; $i < $n; $i++) {
	print $A[$i] * 2, $/;
}
```
###### 数列同士の引き算
```pl
my $n = int(<STDIN>);
my @A = map { int($_) } split ' ', <STDIN>;
my @B = map { int($_) } split ' ', <STDIN>;
for (my $i = 0; $i < $n; $i++) {
	print $A[$i] - $B[$i], $/;
}
```
- - -
##### Python3
###### 数列の和
```py
n = int(input())
A = list(map(int, input().split()))
s = 0
for i in range(n):
	s += A[i]
print(s)
```
###### 数列のA番目からB番目までの和
```py
n, a, b = map(int, input().split())
a -= 1
A = list(map(int, input().split()))
s = 0
for i in range(a, b):
	s += A[i]
print(s)
```
###### 数列の値を全部*2して出力
```py
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
	print(A[i] * 2)
```
###### 数列同士の引き算
```py
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(n):
	print(A[i] - B[i])
```
- - -
##### Ruby
###### 数列の和
```rb
N = gets.to_i
A = gets.split.map(&:to_i)
s = 0
N.times do |i|
	s += A[i]
end
p s
```
###### 数列のA番目からB番目までの和
```rb
N, a, b = gets.split.map(&:to_i)
a -= 1
A = gets.split.map(&:to_i)
s = 0
(a...b).each do |i|
	s += A[i]
end
p s
```
###### 数列の値を全部*2して出力
```rb
N = gets.to_i
A = gets.split.map(&:to_i)
N.times do |i|
	p A[i] * 2
end
```
###### 数列同士の引き算
```rb
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
N.times do |i|
	p A[i] - B[i]
end
```
- - -
##### Scala
###### 数列の和
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	val A = readLine().split(' ').map { _.toInt }
	var s = 0
	for (i <- 0 until n) s += A(i)
	println(s)
}
```
###### 数列のA番目からB番目までの和
```scala
import scala.io.StdIn._

object Main extends App{
	val Array(n, a, b) = readLine().split(' ').map { _.toInt }
	val A = readLine().split(' ').map { _.toInt }
	var s = 0
	for (i <- a - 1 until b) s += A(i)
	println(s)
}
```
###### 数列の値を全部*2して出力
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	val A = readLine().split(' ').map { _.toInt }
	for (i <- 0 until n) println(A(i) * 2)
}
```
###### 数列同士の引き算
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	val A = readLine().split(' ').map { _.toInt }
	val B = readLine().split(' ').map { _.toInt }
	for (i <- 0 until n) println(A(i) - B(i))
}
```
- - -
##### Swift
###### 数列の和
```swift
let n = Int(readLine()!)!
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
var s = 0
for i in 0..<n {
	s += A[i]
}
print(s)
```
###### 数列のA番目からB番目までの和
```swift
let nab = readLine()!.split(separator: " ").compactMap { Int($0) }
let (n, a, b) = (nab[0], nab[1] - 1, nab[2])
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
var s = 0
for i in a..<b {
	s += A[i]
}
print(s)
```
###### 数列の値を全部*2して出力
```swift
let n = Int(readLine()!)!
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
for i in 0..<n {
	print(A[i] * 2)
}
```
###### 数列同士の引き算
```swift
let n = Int(readLine()!)!
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
let B = readLine()!.split(separator: " ").compactMap { Int($0) }
for i in 0..<n {
	print(A[i] - B[i])
}
```