ALGORITHM ๐ค/Baekjoon
๋ฐฑ์ค - 10807
daxx0ne
2023. 3. 23. 10:17
https://www.acmicpc.net/problem/10807
10807๋ฒ: ๊ฐ์ ์ธ๊ธฐ
์ฒซ์งธ ์ค์ ์ ์์ ๊ฐ์ N(1 ≤ N ≤ 100)์ด ์ฃผ์ด์ง๋ค. ๋์งธ ์ค์๋ ์ ์๊ฐ ๊ณต๋ฐฑ์ผ๋ก ๊ตฌ๋ถ๋์ด์ ธ์๋ค. ์ ์งธ ์ค์๋ ์ฐพ์ผ๋ ค๊ณ ํ๋ ์ ์ v๊ฐ ์ฃผ์ด์ง๋ค. ์ ๋ ฅ์ผ๋ก ์ฃผ์ด์ง๋ ์ ์์ v๋ -100๋ณด๋ค ํฌ๊ฑฐ
www.acmicpc.net
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); // ์ ์์ ๊ฐ์
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt(); // ์ ์ ์
๋ ฅ ๋ฐ๊ธฐ
}
int v = sc.nextInt(); // ์ฐพ์ผ๋ ค๋ ์ ์
int count = 0;
for (int j = 0; j < n; j++){
if(v == arr[j]){ // ์
๋ ฅ๋ฐ์ ์ ์ ์ค์ ์ฐพ์ผ๋ ค๋ ์ ์๊ฐ ๋ช ๊ฐ์ธ์ง ์ธ๊ธฐ
count++;
}
}
System.out.println(count);
}
}