알고리즘/Class 224 백준 BOJ 4949번 - 균현잡힌 세상 접근 방법 스택의 원리를 이용하여 구현하면 쉽게 해결할 수 있다. 스택에 왼쪽 괄호를 먼저 저장하고, 그 다음 오는 오른쪽 괄호가 짝이 맞는지 확인하면 완전한 문장인지 체크할 수 있다. 코드 import java.util.Scanner; import java.util.Stack; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s; while(true){ s = in.nextLine(); if(s.equals(".")) break; System.out.println(checkPerfect(s)); } } public static String checkPerfect(S.. 2022. 9. 7. 백준 BOJ 4153번 - 직각삼각형 코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(true) { int x = in.nextInt(); int y = in.nextInt(); int z = in.nextInt(); if(x == 0 && y == 0 && z == 0) break; if((x * x + y * y) == z * z) { System.out.println("right"); } else if(x * x == (y * y + z * z)) { System.out.println("right"); } else if(y * y == (z * z .. 2022. 9. 5. 백준 BOJ 2869번 - 달팽이는 올라가고 싶다 코드 import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine(), " "); int up = Integer.parseInt(st.nextToken()); int down .. 2022. 9. 3. 백준 BOJ 2839번 - 설탕 배달 코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); if (n == 4 || n == 7) System.out.println(-1); else if (n % 5 == 0) System.out.println(n / 5); else if (n % 5 == 1 || n % 5 == 3) System.out.println((n / 5) + 1); else if (n % 5 == 2 || n % 5 == 4) System.out.println((n / 5) + 2); } } 2022. 8. 31. 이전 1 2 3 4 ··· 6 다음