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

paizaラーニングレベルアップ問題集の「何個ある？」をやってみました。
- - -
##### 問題
###### STEP: 1
https://paiza.jp/works/mondai/array_primer/array_primer__search_count_step1
###### STEP: 2
https://paiza.jp/works/mondai/array_primer/array_primer__search_count_step2
###### STEP: 3
https://paiza.jp/works/mondai/array_primer/array_primer__search_count_boss
- - -
##### C
###### STEP: 1
```c
#include <stdio.h>

const int A[] = { 1, 2, 2, 1, 2, 1, 2, 1, 1, 1 };
const int N = 1;

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

const int A[] = { 1, 2, 5, 1, 4, 3, 2, 5, 1, 4 };

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

const vector<int> A = { 1, 2, 2, 1, 2, 1, 2, 1, 1, 1 };
const int N = 1;

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

const vector<int> A = { 1, 2, 5, 1, 4, 3, 2, 5, 1, 4 };

int main() {
	int n;
	cin >> n;
	cout << count(A.begin(), A.end(), n) << 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 << count(A.begin(), A.end(), n) << endl;
	return 0;
}
```
- - -
##### C#
###### STEP: 1
```cs
using System;
using System.Linq;

class Program
{
	static readonly int[] A = { 1, 2, 2, 1, 2, 1, 2, 1, 1, 1 };
	const int N = 1;
	
	public static void Main()
	{
		Console.WriteLine(A.Count(a => a == N));
	}
}
```
###### STEP: 2
```cs
using System;
using System.Linq;

class Program
{
	static readonly int[] A = { 1, 2, 5, 1, 4, 3, 2, 5, 1, 4 };
	
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		Console.WriteLine(A.Count(a => a == n));
	}
}
```
###### STEP: 3
```cs
using System;
using System.Linq;

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(A.Count(a => a == n));
	}
}
```
- - -
##### Go
###### STEP: 1
```go
package main
import "fmt"

var A = []int{ 1, 2, 2, 1, 2, 1, 2, 1, 1, 1 }
const N = 1

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

var A = []int{ 1, 2, 5, 1, 4, 3, 2, 5, 1, 4 }

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

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

public class Main {

	static final int[] A = { 1, 2, 2, 1, 2, 1, 2, 1, 1, 1 };
	static final int N = 1;
	
	public static void main(String[] args) {
		System.out.println(Arrays.stream(A).filter(a -> a == N).count());
	}
}
```
###### STEP: 2
```java
import java.util.*;

public class Main {

	static final int[] A = { 1, 2, 5, 1, 4, 3, 2, 5, 1, 4 };
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		System.out.println(Arrays.stream(A).filter(a -> a == n).count());
	}
}
```
###### 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();
		System.out.println(Arrays.stream(A).filter(a -> a == n).count());
		sc.close();
	}
}
```
- - -
##### JavaScript
###### STEP: 1
```js
const A = [ 1, 2, 2, 1, 2, 1, 2, 1, 1, 1 ];
const N = 1;
console.log(A.filter(a => a === N).length);
```
###### STEP: 2
```js
const A = [ 1, 2, 5, 1, 4, 3, 2, 5, 1, 4 ];
const N = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
console.log(A.filter(a => a === N).length);
```
###### 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.filter(a => a === N).length);
```
- - -
##### Kotlin
###### STEP: 1
```kotlin
fun main() {
	val A = arrayOf(1, 2, 2, 1, 2, 1, 2, 1, 1, 1)
	val N = 1
	println(A.count { it ==  N })
}
```
###### STEP: 2
```kotlin
fun main() {
	val A = arrayOf(1, 2, 5, 1, 4, 3, 2, 5, 1, 4)
	val N = readLine()!!.toInt()
	println(A.count { it ==  N })
}
```
###### STEP: 3
```kotlin
fun main() {
	val (N, _) = readLine()!!.split(' ').map { it.toInt() }
	val A = readLine()!!.split(' ').map { it.toInt() }
	println(A.count { it == N })
}
```
- - -
##### PHP
###### STEP: 1
```php
<?php
	$A = [1, 2, 2, 1, 2, 1, 2, 1, 1, 1];
	$N = 1;
	echo count(array_filter($A, fn($a) => $a === $N)), PHP_EOL;
?>
```
###### STEP: 2
```php
<?php
	$A = [1, 2, 5, 1, 4, 3, 2, 5, 1, 4];
	$N = intval(fgets(STDIN));
	echo count(array_filter($A, fn($a) => $a === $N)), PHP_EOL;
?>
```
###### STEP: 3
```php
<?php
	[$N, $M] = array_map("intval", explode(' ', fgets(STDIN)));
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	echo count(array_filter($A, fn($a) => $a === $N)), PHP_EOL;
?>
```
- - -
##### Perl
###### STEP: 1
```pl
my @A = (1, 2, 2, 1, 2, 1, 2, 1, 1, 1);
my $N = 1;
my $cnt = 0;
foreach $a (@A) {
	$cnt += $a == $N;
}
print "$cnt$/";
```
###### STEP: 2
```pl
my @A = (1, 2, 5, 1, 4, 3, 2, 5, 1, 4);
my $N = 1;
my $cnt = 0;
foreach $a (@A) {
	$cnt += $a == $N;
}
print "$cnt$/";
```
###### STEP: 3
```pl
my ($N, $M) = map { int($_) } split ' ', <STDIN>;
my @A = map { int($_) } split ' ', <STDIN>;
my $cnt = 0;
foreach $a (@A) {
	$cnt += $a == $N;
}
print "$cnt$/";
```
- - -
##### Python3
###### STEP: 1
```py
A = [1, 2, 2, 1, 2, 1, 2, 1, 1, 1]
N = 1
print(A.count(N))
```
###### STEP: 2
```py
A = [1, 2, 5, 1, 4, 3, 2, 5, 1, 4]
N = int(input())
print(A.count(N))
```
###### STEP: 3
```py
N, _ = map(int, input().split())
A = list(map(int, input().split()))
print(A.count(N))
```
- - -
##### Ruby
###### STEP: 1
```rb
A = [1, 2, 2, 1, 2, 1, 2, 1, 1, 1]
N = 1
p A.count(N)
```
###### STEP: 2
```rb
A = [1, 2, 5, 1, 4, 3, 2, 5, 1, 4]
N = gets.to_i
p A.count(N)
```
###### STEP: 3
```rb
N, _ = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
p A.count(N)
```
- - -
##### Scala
###### STEP: 1
```scala
import scala.io.StdIn._

object Main extends App{
	val A = Array(1, 2, 2, 1, 2, 1, 2, 1, 1, 1)
	val N = 1
	println(A.count { _ == N })
}
```
###### STEP: 2
```scala
import scala.io.StdIn._

object Main extends App{
	val A = Array(1, 2, 5, 1, 4, 3, 2, 5, 1, 4)
	val N = readInt()
	println(A.count { _ == N })
}
```
###### STEP: 3
```scala
import scala.io.StdIn._

object Main extends App{
	val Array(n, _) = readLine().split(' ').map { _.toInt }
	val A = readLine().split(' ').map { _.toInt }
	println(A.count { _ == n })
}
```
- - -
##### Swift
###### STEP: 1
```swift
let A = [1, 2, 2, 1, 2, 1, 2, 1, 1, 1]
let N = 1
print(A.filter{ $0 == N }.count)
```
###### STEP: 2
```swift
let A = [1, 2, 5, 1, 4, 3, 2, 5, 1, 4]
let N = Int(readLine()!)!
print(A.filter{ $0 == N }.count)
```
###### STEP: 3
```swift
let N = Int(readLine()!.split(separator: " ")[0])!
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
print(A.filter{ $0 == N }.count)
```