본문 바로가기

Java429

[백준/Java] 2164번 카드2 -Codeimport java.util.ArrayDeque;import java.util.Deque;import java.util.Scanner;public class BOJ2164 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int temp; Deque deque = new ArrayDeque(); // 숫자를 거꾸로 queue에 저장 for (int i = n; i > 0; i--) { deque.push(i); } // deque에 하나만 .. 2025. 9. 25.
[백준/Java] 1874번 스택 수열 -Codeimport java.util.*;public class BOJ1874 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int num; int now = 1; // stack을 deque로 구현 Deque stack = new ArrayDeque(); // 결과 저장할 리스트 List answer = new ArrayList(); for (int i = 0; i = now) { stack.push(now++); .. 2025. 9. 25.
[백준/Java] 12891번 DNA 비밀번호 -Codeimport java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class BOJ12891 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int cnt = 0; int s = Int.. 2025. 9. 19.
[백준/Java] 1940번 주몽 -Codeimport java.util.Arrays;import java.util.Scanner;public class BOJ1940 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); int[] nums = new int[N]; // 고유 번호 입력 받기 for (int i = 0; i 2025. 9. 19.
[백준/Java] 2018번 수들의 합 5 -Codeimport java.util.Scanner;public class BOJ2018 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int cnt = 0; int start = 0; int end = 0; int total = 0; // 투 포인터로 로직 작성 while (end N) { // 현제 구간 합과 n이 작다면 start 빼주고 확장 total -= start; star.. 2025. 9. 18.
[백준/Java] 11659번 구간 합 구하기 4 -Codeimport java.util.Scanner;public class BOJ11659 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); long[] sumList = new long[N + 1]; // 구간 합 리스트 만들기 for (int i = 1; i 2025. 9. 18.