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

paizaラーニングレベルアップ問題集の【ループメニュー】をやってみました。
- - -
##### 問題
###### 未知数個の数の受け取り
https://paiza.jp/works/mondai/loop_problems2/loop_problems2__unknown_int
###### 未知数個の文字列の受け取り
https://paiza.jp/works/mondai/loop_problems2/loop_problems2__unknown_string
###### 奇数だけ出力
https://paiza.jp/works/mondai/loop_problems2/loop_problems2__even_output
###### 割り切れる数だけ出力
https://paiza.jp/works/mondai/loop_problems2/loop_problems2__div_output
###### 偶奇の判定
https://paiza.jp/works/mondai/loop_problems2/loop_problems2__even_odd
- - -
- 1, 2問目は`while`文を使います（のつもりだったが…）
- 3～5問目は`for`文の中に`if`文を使います
	- `filter`関数が使える言語もありますが、今回は封印させて頂きます
- - -
##### C
###### 未知数個の数の受け取り
```c
#include <stdio.h>

int main() {
	int a;
	do {
		scanf("%d", &a);
		printf("%d\n", a);
	} while (a + 1);
	return 0;
}
```
###### 未知数個の文字列の受け取り
```c
#include <stdio.h>
#include <string.h>

int main() {
	char s[11] = "";
	do {
		scanf("%s", s);
		puts(s);
	} while (strcmp(s, "EOF"));
	return 0;
}
```
###### 奇数だけ出力
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		if (a % 2) printf("%d\n", a);
	}
	return 0;
}
```
###### 割り切れる数だけ出力
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		if (a % 3 == 0) printf("%d\n", a);
	}
	return 0;
}
```
###### 偶奇の判定
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		puts(a % 2 ? "odd" : "even");
	}
	return 0;
}
```
- - -
##### C++
###### 未知数個の数の受け取り
```cpp
#include <iostream>
using namespace std;

int main() {
	int a;
	do {
		cin >> a;
		cout << a << endl;
	} while (a + 1);
	return 0;
}
```
###### 未知数個の文字列の受け取り
```cpp
#include <iostream>
using namespace std;

int main() {
	string s;
	do {
		cin >> s;
		cout << s << endl;
	} while (s != "EOF");
	return 0;
}
```
###### 奇数だけ出力
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 2) cout << a << endl;
	}
	return 0;
}
```
###### 割り切れる数だけ出力
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 3 == 0) cout << a << endl;
	}
	return 0;
}
```
###### 偶奇の判定
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		cout << (a % 2 ? "odd" : "even") << endl;
	}
	return 0;
}
```
- - -
##### C#
###### 未知数個の数の受け取り
```cs
using System;

class Program
{
	public static void Main()
	{
		int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		foreach (int a in A) {
			Console.WriteLine(a);
			if (a == -1) break;
		}
	}
}
```
###### 未知数個の文字列の受け取り
```cs
using System;

class Program
{
	public static void Main()
	{
		string[] S = Console.ReadLine().Split();
		foreach (string s in S) {
			Console.WriteLine(s);
			if ("EOF".Equals(s)) break;
		}
	}
}
```
###### 奇数だけ出力
```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++) if (A[i] % 2 != 0) Console.WriteLine(A[i]);
	}
}
```
###### 割り切れる数だけ出力
```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++) if (A[i] % 3 == 0) Console.WriteLine(A[i]);
	}
}
```
###### 偶奇の判定
```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 == 0 ? "even" : "odd");
	}
}
```
- - -
##### Go
###### 未知数個の数の受け取り
```go
package main
import "fmt"

func main() {
	a := 0
	for a != -1 {
		fmt.Scan(&a)
		fmt.Println(a)
	}
}
```
###### 未知数個の文字列の受け取り
```go
package main
import "fmt"

func main() {
	s := ""
	for s != "EOF" {
		fmt.Scan(&s)
		fmt.Println(s)
	}
}
```
###### 奇数だけ出力
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if a % 2 != 0 {
			fmt.Println(a)
		}
	}
}
```
###### 割り切れる数だけ出力
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if a % 3 == 0 {
			fmt.Println(a)
		}
	}
}
```
###### 偶奇の判定
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if a % 2 == 0 {
			fmt.Println("even")
		} else {
			fmt.Println("odd")
		}
	}
}
```
- - -
##### Java
###### 未知数個の数の受け取り
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a;
		do {
			a = sc.nextInt();
			System.out.println(a);
		} while (a != -1);
		sc.close();
	}
}
```
###### 未知数個の文字列の受け取り
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s;
		do {
			s = sc.next();
			System.out.println(s);
		} while (!"EOF".equals(s));
		sc.close();
	}
}
```
###### 奇数だけ出力
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int[] A = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		sc.close();
		for (int i = 0; i < n; i++) if (A[i] % 2 != 0) System.out.println(A[i]);
	}
}
```
###### 割り切れる数だけ出力
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int[] A = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		sc.close();
		for (int i = 0; i < n; i++) if (A[i] % 3 == 0) System.out.println(A[i]);
	}
}
```
###### 偶奇の判定
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int[] A = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		sc.close();
		for (int i = 0; i < n; i++) System.out.println(A[i] % 2 == 0 ? "even" : "odd");
	}
}
```
- - -
##### JavaScript
###### 未知数個の数の受け取り
```js
const A = require("fs").readFileSync("/dev/stdin", "utf8").split(' ').map(Number);
var i = 0;
do {
	console.log(A[i]);
} while (A[i++] !== -1);
```
###### 未知数個の文字列の受け取り
```js
const S = require("fs").readFileSync("/dev/stdin", "utf8").trim().split(' ');
var i = 0;
do {
	console.log(S[i]);
} while (S[i++] !== "EOF");
```
###### 奇数だけ出力
```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++) if(A[i] % 2) console.log(A[i]);
```
###### 割り切れる数だけ出力
```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++) if(A[i] % 3 == 0) console.log(A[i]);
```
###### 偶奇の判定
```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 ? "odd" : "even");
```
- - -
##### Kotlin
###### 未知数個の数の受け取り
```kotlin
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	var a = 0
	while (a != -1) {
		a = sc.nextInt()
		println(a)
	}
	sc.close()
}
```
###### 未知数個の文字列の受け取り
```kotlin
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	var s = ""
	while (!"EOF".equals(s)) {
		s = sc.next()
		println(s)
	}
	sc.close()
}
```
###### 奇数だけ出力
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	val A = readLine()!!.split(' ').map { it.toInt() }
	for (i in 0 until n) if (A[i] % 2 != 0) println(A[i])
}
```
###### 割り切れる数だけ出力
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	val A = readLine()!!.split(' ').map { it.toInt() }
	for (i in 0 until n) if (A[i] % 3 == 0) println(A[i])
}
```
###### 偶奇の判定
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	val A = readLine()!!.split(' ').map { it.toInt() }
	for (i in 0 until n) println(if (A[i] % 2 == 0) "even" else "odd")
}
```
- - -
##### PHP
###### 未知数個の数の受け取り
```php
<?php
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	foreach ($A as $a) {
		echo $a, PHP_EOL;
		if ($a === -1) break;
	}
?>
```
###### 未知数個の文字列の受け取り
```php
<?php
	$S = explode(' ', trim(fgets(STDIN)));
	foreach ($S as $s) {
		echo $s, PHP_EOL;
		if ($s === "EOF") break;
	}
?>
```
###### 奇数だけ出力
```php
<?php
	$n = intval(fgets(STDIN));
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	for ($i = 0; $i < $n; $i++) if ($A[$i] % 2) echo $A[$i], PHP_EOL;
?>
```
###### 割り切れる数だけ出力
```php
<?php
	$n = intval(fgets(STDIN));
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	for ($i = 0; $i < $n; $i++) if ($A[$i] % 3 === 0) echo $A[$i], PHP_EOL;
?>
```
###### 偶奇の判定
```php
<?php
	$n = intval(fgets(STDIN));
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	for ($i = 0; $i < $n; $i++) echo $A[$i] % 2 ? "odd" : "even", PHP_EOL;
?>
```
- - -
##### Perl
###### 未知数個の数の受け取り
```pl
my @A = map { int($_) } split ' ', <STDIN>;
for my $a (@A) {
	print "$a$/";
	last if $a == -1;
}
```
###### 未知数個の文字列の受け取り
```pl
my @S = split ' ', <STDIN>;
for my $s (@S) {
	chomp($s);
	print "$s$/";
	last if $s eq "EOF";
}
```
###### 奇数だけ出力
```pl
my $n = int(<STDIN>);
my @A = map { int($_) } split ' ', <STDIN>;
for (my $i = 0; $i < $n; $i++) {
	if ($A[$i] % 2) {
		print "$A[$i]$/";
	}
}
```
###### 割り切れる数だけ出力
```pl
my $n = int(<STDIN>);
my @A = map { int($_) } split ' ', <STDIN>;
for (my $i = 0; $i < $n; $i++) {
	if ($A[$i] % 3 == 0) {
		print "$A[$i]$/";
	}
}
```
###### 偶奇の判定
```pl
my $n = int(<STDIN>);
my @A = map { int($_) } split ' ', <STDIN>;
for (my $i = 0; $i < $n; $i++) {
	print $A[$i] % 2 ? "odd" : "even", $/;
}
```
- - -
##### Python3
###### 未知数個の数の受け取り
```py
A = list(map(int, input().split()))
for a in A:
	print(a)
	if a == -1:
		break
```
###### 未知数個の文字列の受け取り
```py
S = input().split()
for s in S:
	print(s)
	if s == "EOF":
		break
```
###### 奇数だけ出力
```py
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
	if A[i] % 2:
		print(A[i])
```
###### 割り切れる数だけ出力
```py
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
	if A[i] % 3 == 0:
		print(A[i])
```
###### 偶奇の判定
```py
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
	print("odd" if A[i] % 2 else "even")
```
- - -
##### Ruby
###### 未知数個の数の受け取り
```rb
A = gets.split.map(&:to_i)
A.each do |a|
	p a
	if a == -1
		break
	end
end
```
###### 未知数個の文字列の受け取り
```rb
S = gets.chomp.split
S.each do |s|
	puts s
	if s == "EOF"
		break
	end
end
```
###### 奇数だけ出力
```rb
N = gets.to_i
A = gets.split.map(&:to_i)
N.times do |i|
	if A[i] % 2 != 0
		p A[i]
	end
end
```
###### 割り切れる数だけ出力
```rb
N = gets.to_i
A = gets.split.map(&:to_i)
N.times do |i|
	if A[i] % 3 == 0
		p A[i]
	end
end
```
###### 偶奇の判定
```rb
N = gets.to_i
A = gets.split.map(&:to_i)
N.times do |i|
	puts A[i] % 2 == 0 ? "even" : "odd"
end
```
- - -
##### Scala
###### 未知数個の数の受け取り
```scala
import java.util._

object Main extends App{
	val sc = new Scanner(System.in)
	var a = 0
	do {
		a = sc.nextInt()
		println(a)
	} while (a != -1)
	sc.close()
}
```
###### 未知数個の文字列の受け取り
```scala
import java.util._

object Main extends App{
	val sc = new Scanner(System.in)
	var s = ""
	do {
		s = sc.next()
		println(s)
	} while (!"EOF".equals(s))
	sc.close()
}
```
###### 奇数だけ出力
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	val A = readLine().split(' ').map { _.toInt }
	for (i <- 0 until n) if (A(i) % 2 != 0) println(A(i))
}
```
###### 割り切れる数だけ出力
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	val A = readLine().split(' ').map { _.toInt }
	for (i <- 0 until n) if (A(i) % 3 == 0) println(A(i))
}
```
###### 偶奇の判定
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	val A = readLine().split(' ').map { _.toInt }
	for (i <- 0 until n) println(if (A(i) % 2 == 0) "even" else "odd")
}
```
- - -
##### Swift
###### 未知数個の数の受け取り
```swift
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
for a in A {
	print(a)
	if a == -1 {
		break
	}
}
```
###### 未知数個の文字列の受け取り
```swift
let S = readLine()!.split(separator: " ")
for s in S {
	print(s)
	if s == "EOF" {
		break
	}
}
```
###### 奇数だけ出力
```swift
let n = Int(readLine()!)!
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
for i in 0..<n {
	if A[i] % 2 != 0 {
		print(A[i])
	}
}
```
###### 割り切れる数だけ出力
```swift
let n = Int(readLine()!)!
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
for i in 0..<n {
	if A[i] % 3 == 0 {
		print(A[i])
	}
}
```
###### 偶奇の判定
```swift
let n = Int(readLine()!)!
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
for i in 0..<n {
	print(A[i] % 2 == 0 ? "even" : "odd")
}
```
- - -
3問目は「奇数だけ出力」なのにURLの末尾が`even_output`...