paizaラーニングレベルアップ問題集の「何番目にある？」をやってみた。

paizaラーニングレベルアップ問題集の「何番目にある？」をやってみました。
- - -
##### 問題
###### STEP: 1
https://paiza.jp/works/mondai/array_primer/array_primer__search_i-th_step1
###### STEP: 2
https://paiza.jp/works/mondai/array_primer/array_primer__search_i-th_step2
###### STEP: 3
https://paiza.jp/works/mondai/array_primer/array_primer__search_i-th_step3
- - -
プログラム内部では配列の添字は0始まりですが、出力は「左端を1番目とします。」とあります。
- - -
##### C
###### STEP: 1
```c
#include <stdio.h>

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

int main() {
	size_t m = sizeof(A) / sizeof(A[0]);
	for (size_t i = 0; i < m; i++) {
		if (A[i] == N) {
			printf("%zu\n", i + 1);
			break;
		}
	}
	return 0;
}
```
###### STEP: 2
```c
#include <stdio.h>

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

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

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

const vector<int> A = { 1, 10, 2, 9, 3, 8, 4, 7, 5, 6 };
const int N = 8;

int main() {
	cout << find(A.begin(), A.end(), N) - A.begin() + 1 << endl;
	return 0;
}
```
###### STEP: 2
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

int main() {
	int N;
	cin >> N;
	cout << find(A.begin(), A.end(), N) - A.begin() + 1 << 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(M);
	for (int i = 0; i < M; i++) cin >> A[i];
	cout << find(A.begin(), A.end(), N) - A.begin() + 1 << endl;
	return 0;
}
```
- - -
##### C#
###### STEP: 1
```cs
using System;

class Program
{
	static readonly int[] A = { 1, 10, 2, 9, 3, 8, 4, 7, 5, 6 };
	const int N = 8;
	
	public static void Main()
	{
		Console.WriteLine(Array.IndexOf(A, N) + 1);
	}
}
```
###### STEP: 2
```cs
using System;

class Program
{
	static readonly int[] A = { 1, 5, 9, 7, 3, 2, 4, 8, 6, 10 };
	
	public static void Main()
	{
		int N = int.Parse(Console.ReadLine());
		Console.WriteLine(Array.IndexOf(A, N) + 1);
	}
}
```
###### STEP: 3
```cs
using System;

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

var A = []int{ 1, 10, 2, 9, 3, 8, 4, 7, 5, 6 }
const N = 8

func main() {
	for i, a := range(A) {
		if a == N {
			fmt.Println(i + 1)
			break
		}
	}
}
```
###### STEP: 2
```go
package main
import "fmt"

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

func main() {
	var N int
	fmt.Scan(&N)
	for i, a := range(A) {
		if a == N {
			fmt.Println(i + 1)
			break
		}
	}
}
```
###### STEP: 3
```go
package main
import "fmt"

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

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	A := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&A[i])
	}
	for i, a := range(A) {
		if a == N {
			fmt.Println(i + 1)
			break
		}
	}
}
```
- - -
##### Java
###### STEP: 1
```java
import java.util.*;

public class Main {

	static final Integer[] A = { 1, 10, 2, 9, 3, 8, 4, 7, 5, 6 };
	static final int N = 8;
	
	public static void main(String[] args) {
		System.out.println(Arrays.asList(A).indexOf(N) + 1);
	}
}
```
###### STEP: 2
```java
import java.util.*;

public class Main {

	static final Integer[] A = { 1, 10, 2, 9, 3, 8, 4, 7, 5, 6 };
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		System.out.println(Arrays.asList(A).indexOf(N) + 1);
	}
}
```
###### 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();
		Integer[] A = new Integer[m];
		for (int i = 0; i < m; i++) A[i] = sc.nextInt();
		sc.close();
		System.out.println(Arrays.asList(A).indexOf(n) + 1);
	}
}
```
- - -
##### JavaScript
###### STEP: 1
```js
const A = [ 1, 10, 2, 9, 3, 8, 4, 7, 5, 6 ];
const N = 8;
console.log(A.indexOf(N) + 1);
```
###### STEP: 2
```js
const A = [ 1, 5, 9, 7, 3, 2, 4, 8, 6, 10 ];
const N = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
console.log(A.indexOf(N) + 1);
```
###### 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.indexOf(N) + 1);
```
- - -
##### Kotlin
###### STEP: 1
```kotlin
fun main() {
	val A = arrayOf(1, 10, 2, 9, 3, 8, 4, 7, 5, 6)
	val N = 8
	println(A.indexOf(N) + 1)
}
```
###### STEP: 2
```kotlin
fun main() {
	val A = arrayOf(1, 5, 9, 7, 3, 2, 4, 8, 6, 10)
	val N = readLine()!!.toInt()
	println(A.indexOf(N) + 1)
}
```
###### STEP: 3
```kotlin
fun main() {
	val N = readLine()!!.split(' ')[0].toInt()
	val A = readLine()!!.split(' ').map { it.toInt() }
	println(A.indexOf(N) + 1)
}
```
- - -
##### PHP
###### STEP: 1
```php
<?php
	$A = [ 1, 10, 2, 9, 3, 8, 4, 7, 5, 6 ];
	$N = 8;
	echo array_search($N, $A) + 1, PHP_EOL;
?>
```
###### STEP: 2
```php
<?php
	$A = [ 1, 5, 9, 7, 3, 2, 4, 8, 6, 10 ];
	$N = intval(fgets(STDIN));
	echo array_search($N, $A) + 1, PHP_EOL;
?>
```
###### STEP: 3
```php
<?php
	$N = intval(explode(' ', fgets(STDIN))[0]);
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	echo array_search($N, $A) + 1, PHP_EOL;
?>
```
- - -
##### Perl
###### STEP: 1
```pl
my @A = (1, 10, 2, 9, 3, 8, 4, 7, 5, 6);
my $N = 8;
my $M = scalar(@A);
for (my $i = 0; $i < $M; $i++) {
	if ($A[$i] == $N) {
		print $i + 1, $/;
		last;
	}
}
```
###### STEP: 2
```pl
my @A = (1, 5, 9, 7, 3, 2, 4, 8, 6, 10);
my $N = int(<STDIN>);
my $M = scalar(@A);
for (my $i = 0; $i < $M; $i++) {
	if ($A[$i] == $N) {
		print $i + 1, $/;
		last;
	}
}
```
###### STEP: 3
```pl
my ($N, $M) = map { int($_) } split ' ', <STDIN>;
my @A = map { int($_) } split ' ', <STDIN>;
for (my $i = 0; $i < $M; $i++) {
	if ($A[$i] == $N) {
		print $i + 1, $/;
		last;
	}
}
```
- - -
##### Python3
###### STEP: 1
```py
A = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]
N = 8
print(A.index(N) + 1)
```
###### STEP: 2
```py
A = [1, 5, 9, 7, 3, 2, 4, 8, 6, 10]
N = int(input())
print(A.index(N) + 1)
```
###### STEP: 3
```py
N = int(input().split()[0])
A = list(map(int, input().split()))
print(A.index(N) + 1)
```
- - -
##### Ruby
###### STEP: 1
```rb
A = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]
N = 8
p A.index(N) + 1
```
###### STEP: 2
```rb
A = [1, 5, 9, 7, 3, 2, 4, 8, 6, 10]
N = gets.to_i
p A.index(N) + 1
```
###### STEP: 3
```rb
N, _ = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
p A.index(N) + 1
```
- - -
##### Scala
###### STEP: 1
```scala
object Main extends App{
	val A = Array(1, 10, 2, 9, 3, 8, 4, 7, 5, 6)
	val N = 8
	println(A.indexOf(N) + 1)
}
```
###### STEP: 2
```scala
import scala.io.StdIn._

object Main extends App{
	val A = Array(1, 5, 9, 7, 3, 2, 4, 8, 6, 10)
	val N = readInt()
	println(A.indexOf(N) + 1)
}
```
###### STEP: 3
```scala
import scala.io.StdIn._

object Main extends App{
	val N = readLine().split(' ')(0).toInt
	val A = readLine().split(' ').map { _.toInt }
	println(A.indexOf(N) + 1)
}
```
- - -
##### Swift
###### STEP: 1
```swift
let A = [1, 10, 2, 9, 3, 8, 4, 7, 5, 6]
let N = 8
print(A.firstIndex(of: N)! + 1)
```
###### STEP: 2
```swift
let A = [1, 5, 9, 7, 3, 2, 4, 8, 6, 10]
let N = Int(readLine()!)!
print(A.firstIndex(of: N)! + 1)
```
###### STEP: 3
```swift
let N = Int(readLine()!.split(separator: " ")[0])!
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
print(A.firstIndex(of: N)! + 1)
```