paizaラーニングレベルアップ問題集の「配列に含まれている？」をやってみた。

paizaラーニングレベルアップ問題集の「配列に含まれている？」をやってみました。
- - -
##### 問題
###### STEP: 1
https://paiza.jp/works/mondai/array_primer/array_primer__search_include_step1
###### STEP: 2
https://paiza.jp/works/mondai/array_primer/array_primer__search_include_step2
###### STEP: 3
https://paiza.jp/works/mondai/array_primer/array_primer__search_include_step3
- - -
##### C
###### STEP: 1
```c
#include <stdio.h>

const int A[] = { 10, 13, 21, 1, 6, 51, 10, 8, 15, 6 };
const int M = 6;

int main() {
	size_t n = sizeof(A) / sizeof(A[0]);
	for (size_t i = 0; i <= n; i++) {
		if (i == n) {
			puts("No");
		} else if (A[i] == M) {
			puts("Yes");
			break;
		}
	}
	return 0;
}
```
###### STEP: 2
```c
#include <stdio.h>

const int A[] = { 5, 12, 6, 84, 14, 25, 44, 3, 7, 20 };

int main() {
	size_t n = sizeof(A) / sizeof(A[0]);
	int m;
	scanf("%d", &m);
	for (size_t i = 0; i <= n; i++) {
		if (i == n) {
			puts("No");
		} else if (A[i] == m) {
			puts("Yes");
			break;
		}
	}
	return 0;
}
```
###### STEP: 3
```c
#include <stdio.h>

int main() {
	size_t n;
	int m;
	scanf("%zu %d", &n, &m);
	int A[n];
	for (size_t i = 0; i < n; i++) scanf("%d", &A[i]);
	for (size_t i = 0; i <= n; i++) {
		if (i == n) {
			puts("No");
		} else if (A[i] == m) {
			puts("Yes");
			break;
		}
	}
	return 0;
}
```
- - -
##### C++
###### STEP: 1
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const vector<int> A = { 10, 13, 21, 1, 6, 51, 10, 8, 15, 6 };
const int M = 6;

int main() {
	cout << (find(A.begin(), A.end(), M) == A.end() ? "No" : "Yes") << endl;
	return 0;
}
```
###### STEP: 2
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const vector<int> A = { 5, 12, 6, 84, 14, 25, 44, 3, 7, 20 };

int main() {
	int n;
	cin >> n;
	cout << (find(A.begin(), A.end(), n) == A.end() ? "No" : "Yes") << endl;
	return 0;
}
```
###### STEP: 3
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> A(n);
	for (int i = 0; i < n; i++) cin >> A[i];
	cout << (find(A.begin(), A.end(), m) == A.end() ? "No" : "Yes") << endl;
	return 0;
}
```
- - -
##### C#
###### STEP: 1
```cs
using System;

class Program
{
	static readonly int[] A = { 10, 13, 21, 1, 6, 51, 10, 8, 15, 6 };
	const int M = 6;
	
	public static void Main()
	{
		Console.WriteLine(Array.IndexOf(A, M) == -1 ? "No" : "Yes");
	}
}
```
###### STEP: 2
```cs
using System;

class Program
{
	static readonly int[] A = { 5, 12, 6, 84, 14, 25, 44, 3, 7, 20 };
	
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		Console.WriteLine(Array.IndexOf(A, n) == -1 ? "No" : "Yes");
	}
}
```
###### STEP: 3
```cs
using System;

class Program
{
	public static void Main()
	{
		int m = int.Parse(Console.ReadLine().Split()[1]);
		int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		Console.WriteLine(Array.IndexOf(A, m) == -1 ? "No" : "Yes");
	}
}
```
- - -
##### Go
###### STEP: 1
```go
package main
import "fmt"

var A = []int{ 10, 13, 21, 1, 6, 51, 10, 8, 15, 6 }
const M = 6

func main() {
	n := len(A)
	for i := 0; i <= n; i++ {
		if i == n {
			fmt.Println("No")
		} else if A[i] == M {
			fmt.Println("Yes")
			break
		}
	}
}
```
###### STEP: 2
```go
package main
import "fmt"

var A = []int{ 5, 12, 6, 84, 14, 25, 44, 3, 7, 20 }

func main() {
	n := len(A)
	var m int
	fmt.Scan(&m)
	for i := 0; i <= n; i++ {
		if i == n {
			fmt.Println("No")
		} else if A[i] == m {
			fmt.Println("Yes")
			break
		}
	}
}
```
###### STEP: 3
```go
package main
import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	A := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&A[i])
	}
	for i := 0; i <= n; i++ {
		if i == n {
			fmt.Println("No")
		} else if A[i] == m {
			fmt.Println("Yes")
			break
		}
	}
}
```
- - -
##### Java
###### STEP: 1
```java
import java.util.*;

public class Main {

	static final int[] A = { 10, 13, 21, 1, 6, 51, 10, 8, 15, 6 };
	static final int M = 6;
	
	public static void main(String[] args) {
		System.out.println(Arrays.stream(A).anyMatch(a -> a == M) ? "Yes" : "No");
	}
}
```
```java
import java.util.*;

public class Main {

	static final Integer[] A = { 10, 13, 21, 1, 6, 51, 10, 8, 15, 6 };
	static final int M = 6;
	
	public static void main(String[] args) {
		System.out.println(Arrays.asList(A).contains(M) ? "Yes" : "No");
	}
}
```
###### STEP: 2
```java
import java.util.*;

public class Main {

	static final int[] A = { 5, 12, 6, 84, 14, 25, 44, 3, 7, 20 };
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		sc.close();
		System.out.println(Arrays.stream(A).anyMatch(a -> a == m) ? "Yes" : "No");
	}
}
```
```java
import java.util.*;

public class Main {

	static final Integer[] A = { 5, 12, 6, 84, 14, 25, 44, 3, 7, 20 };
	static final int M = 6;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		sc.close();
		System.out.println(Arrays.asList(A).contains(M) ? "Yes" : "No");
	}
}
```
###### STEP: 3
```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();
		sc.nextLine();
		int[] A = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		sc.close();
		System.out.println(Arrays.stream(A).anyMatch(a -> a == m) ? "Yes" : "No");
	}
}
```
- - -
##### JavaScript
###### STEP: 1
```js
const A = [ 10, 13, 21, 1, 6, 51, 10, 8, 15, 6 ];
const M = 6
console.log(A.includes(M) ? "Yes" : "No");
```
###### STEP: 2
```js
const A = [ 5, 12, 6, 84, 14, 25, 44, 3, 7, 20 ];
const m = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
console.log(A.includes(m) ? "Yes" : "No");
```
###### STEP: 3
```js
const [[n, m], A] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map(s => s.split(' ').map(Number));
console.log(A.includes(m) ? "Yes" : "No");
```
- - -
##### Kotlin
###### STEP: 1
```kotlin
fun main() {
	val A = arrayOf(10, 13, 21, 1, 6, 51, 10, 8, 15, 6)
	val M = 6
	println(if (A.contains(M)) "Yes" else "No")
}
```
###### STEP: 2
```kotlin
fun main() {
	val A = arrayOf(5, 12, 6, 84, 14, 25, 44, 3, 7, 20)
	val M = readLine()!!.toInt()
	println(if (A.contains(M)) "Yes" else "No")
}
```
###### STEP: 3
```kotlin
fun main() {
	val (_, m) = readLine()!!.split(' ').map { it.toInt() }
	val A = readLine()!!.split(' ').map { it.toInt() }
	println(if (A.contains(m)) "Yes" else "No")
}
```
- - -
##### PHP
###### STEP: 1
```php
<?php
	$A = [ 10, 13, 21, 1, 6, 51, 10, 8, 15, 6 ];
	$M = 6;
	echo in_array($M, $A) ? "Yes" : "No", PHP_EOL;
?>
```
###### STEP: 2
```php
<?php
	$A = [ 5, 12, 6, 84, 14, 25, 44, 3, 7, 20 ];
	$m = intval(fgets(STDIN));
	echo in_array($m, $A) ? "Yes" : "No", PHP_EOL;
?>
```
###### STEP: 3
```php
<?php
	[$n, $m] = array_map("intval", explode(' ', fgets(STDIN)));
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	echo in_array($m, $A) ? "Yes" : "No", PHP_EOL;
?>
```
- - -
##### Perl
###### STEP: 1
```pl
my @A = (10, 13, 21, 1, 6, 51, 10, 8, 15, 6);
my $M = 6;
my $f = 0;
foreach $a (@A) {
	if ($a == $M) {
		$f = 1;
		last;
	}
}
print $f ? "Yes" : "No", $/;
```
###### STEP: 2
```pl
my @A = (5, 12, 6, 84, 14, 25, 44, 3, 7, 20);
my $M = int(<STDIN>);
my $f = 0;
foreach $a (@A) {
	if ($a == $M) {
		$f = 1;
		last;
	}
}
print $f ? "Yes" : "No", $/;
```
###### STEP: 3
```pl
my ($N, $M) = map { int($_) } split ' ', <STDIN>;
my @A = map { int($_) } split ' ', <STDIN>;
my $f = 0;
foreach $a (@A) {
	if ($a == $M) {
		$f = 1;
		last;
	}
}
print $f ? "Yes" : "No", $/;
```
- - -
##### Python3
###### STEP: 1
```py
A = [ 10, 13, 21, 1, 6, 51, 10, 8, 15, 6 ]
M = 6
print("Yes" if M in A else "No")
```
###### STEP: 2
```py
A = [ 5, 12, 6, 84, 14, 25, 44, 3, 7, 20 ]
M = int(input())
print("Yes" if M in A else "No")
```
###### STEP: 3
```py
_, M = map(int, input().split())
A = list(map(int, input().split()))
print("Yes" if M in A else "No")
```
- - -
##### Ruby
###### STEP: 1
```rb
A = [ 10, 13, 21, 1, 6, 51, 10, 8, 15, 6 ]
M = 6
puts A.include?(M) ? "Yes" : "No"
```
###### STEP: 2
```rb
A = [ 5, 12, 6, 84, 14, 25, 44, 3, 7, 20 ]
M = gets.to_i
puts A.include?(M) ? "Yes" : "No"
```
###### STEP: 3
```rb
_, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
puts A.include?(M) ? "Yes" : "No"
```
- - -
##### Scala
###### STEP: 1
```scala
object Main extends App{
	val A = Array(10, 13, 21, 1, 6, 51, 10, 8, 15, 6)
	val M = 6
	println(if (A.contains(M)) "Yes" else "No")
}
```
###### STEP: 2
```scala
import scala.io.StdIn._

object Main extends App{
	val A = Array(5, 12, 6, 84, 14, 25, 44, 3, 7, 20)
	val M = readInt()
	println(if (A.contains(M)) "Yes" else "No")
}
```
###### STEP: 3
```scala
import scala.io.StdIn._

object Main extends App{
	val Array(_, m) = readLine().split(' ').map { _.toInt }
	val A = readLine().split(' ').map { _.toInt }
	println(if (A.contains(m)) "Yes" else "No")
}
```
- - -
##### Swift
###### STEP: 1
```swift
let A = [10, 13, 21, 1, 6, 51, 10, 8, 15, 6]
let M = 6
print(A.contains(M) ? "Yes" : "No")
```
###### STEP: 2
```swift
let A = [5, 12, 6, 84, 14, 25, 44, 3, 7, 20]
let M = Int(readLine()!)!
print(A.contains(M) ? "Yes" : "No")
```
###### STEP: 3
```swift
let M = Int(readLine()!.split(separator: " ")[1])!
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
print(A.contains(M) ? "Yes" : "No")
```