충분히 쌓여가는
백준[Java] 10807번 개수 세기 본문
https://www.acmicpc.net/problem/10807
문제풀이 1
import java.util.Scanner;
public class _10807_1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] arr = new int[N];
int count = 0;
for (int i = 0; i < N; i++) {
arr[i] = sc.nextInt();
}
int find = sc.nextInt();
for (int i = 0; i < arr.length; i++) {
if (find == arr[i])
count += 1;
}
System.out.println(count);
}
}
문제풀이 2
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class _10807_2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] arr = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i <arr.length; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int find = Integer.parseInt(br.readLine());
int count = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] == find)
count++;
}
System.out.println(count);
br.close();
}
}
문제풀이 3
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class _10807_3 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
int[] arr = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i <arr.length; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int find = Integer.parseInt(br.readLine());
int count = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] == find)
count++;
}
bw.write(count + "\n"); // 여기서 "\n"을 안해주면 오류가 나는데 왜인지 모르겠음
bw.flush();
bw.close();
br.close();
}
}
'IT > Java[백준]' 카테고리의 다른 글
백준[Java] 10871번 최소,최대 (0) | 2023.02.27 |
---|---|
백준[Java] 10871번 X보다 작은 수 (0) | 2023.02.26 |
백준[Java] 10951번 A+B-4 (hasNextInt 사용 [중요!]) (1) | 2023.02.23 |
백준[Java] 10952번 A+B-5 [charAt 사용] (0) | 2023.02.22 |
백준[Java] 2439번 별 찍기 -2 (0) | 2023.02.21 |