본문 바로가기

코딩 테스트30

백준 10448번 유레카이론(자바,java,JAVA) public class Main { static int answer = 0; public static void main(String args[]) throws Exception { ​ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); ​ int testcase = Integer.parseInt(br.readLine()); ​ for(int i = 0 ; i < testcase ; i++ ) { long t = Long.parseLong(br.readLine()); // 삼각수 t를 받아오고 판별한다. // 조건 1.삼각수 세개로 표현한다. 2. 삼각수가.. 2023. 1. 11.
백준 2231번 분해합(자바,java,JAVA) 탐색의 시작점 찾아내서 푼 케이스도 존재하더라. 최소 몇부터 시작해야하는지 public class Main { public static void main(String args[]) throws Exception { ​ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //StringBuilder sb = new StringBuilder(); ​ int num = Integer.parseInt(br.readLine()); ​ String checklength = Integer.toString(num); int length = checklength.length() -1 ; // 1000이라면 길이값이 4가나와서 -1해준다. ​.. 2023. 1. 11.
백준 15740번 A+B - 9(자바,java,JAVA) 자료형의 범위 문제 처음에는 long타입으로 초기화해서 받았는데 75점. 이상해서 double로...0점. 찾아보니 BigInteger라는 타입이 존재하고 거의 무한대로 가져간대..우찌알어.. int는 거의 10^9정도로 받아주고 (2,147,483,647) long은 거의 10^18정도 받아준다 정확히는 (9,223,372,036,854,775,807) import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); BigInteger a, b.. 2023. 1. 11.
백준 1260번 DFS와 BFS(자바,java,JAVA) import java.io.*; import java.util.*; public class Main { static StringBuilder sb = new StringBuilder(); public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int v = Integer.parseInt(st.nextToken()); // 정점 int e = Integer.parseInt(st.nextToken()); // 간선 int sta.. 2023. 1. 11.
백준 18429번 근손실(자바,java,JAVA) 재귀에서 ptotal값도 visited처럼 되돌려야하는데 안했다. 저렇게 주석처리한것처럼 처리하면 또 잘된다...너무어렵넹 import java.io.*; import java.util.*; public class Main { public static int ncount = 0; /* output setting */ // static StringBuilder sb = new StringBuilder(); public static void main(String[] args) throws IOException { /* input reader */ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); /* input tokenize.. 2023. 1. 11.
백준 1406번 에디터(자바,java,JAVA) 주석으로 달아놨지만 명령어 행위들이 왼쪽스택 오른쪽스택으로 주고받게 끔 되어있다. 그림을 그려보면 확실히 알 수 있다. import java.io.*; import java.util.*; public class Main { public static int ncount = 0; /* output setting */ // static StringBuilder sb = new StringBuilder(); public static void main(String[] args) throws IOException { /* input reader */ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //ArrayList list = .. 2023. 1. 11.
2577번 숫자의 개수(자바, java) - 백준 문제풀이 import java.io.*; import java.util.*; public class Main { //static int ncheck = 0; //static int nnum = 0; /* output setting */ static StringBuilder sb = new StringBuilder(); public static void main(String[] args) throws IOException { /* input reader */ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //ArrayList list = new ArrayList(); int a = Integer.parseInt(br.readLin.. 2023. 1. 11.
1475번 방번호(자바, java) - 백준 문제풀이 import java.io.*; import java.util.*; public class Main { //static int ncheck = 0; //static int nnum = 0; /* output setting */ static StringBuilder sb = new StringBuilder(); public static void main(String[] args) throws IOException { /* input reader */ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //ArrayList list = new ArrayList(); String sword = br.readLine(); char[.. 2023. 1. 11.
5397번 키로거(자바, java) - 백준 문제풀이 커서에 집착하다가 엄청 틀렸다. 시간초과와 함께.. 스택을 잘그려보면 커서라는 것이 필요가없다. import java.io.*; import java.util.*; public class Main { // static int ncheck = 0; // static int nnum = 0; /* output setting */ static StringBuilder sb = new StringBuilder(); public static void main(String[] args) throws IOException { /* input reader */ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // ArrayList li.. 2023. 1. 11.
1158번 요세푸스 문제(자바, java) - 백준 문제풀이 0 1 2 3 4 5 6 1 2 3 4 5 6 7 ​ size = 7 cursor = 2 remove = 3 -------------------- 0 1 2 3 4 5 6 1 2 4 5 6 7 ​ size = 6 cursor = 4 remove = 6 -------------------- 0 1 2 3 4 5 6 1 2 4 5 7 ​ size = 5 cursor = 1 remove = 2 ------------------ 0 1 2 3 4 5 6 1 4 5 7t ​ size = 4 cursor = 3 remove = 7 -------------------- 0 1 2 3 4 5 6 1 4 5 ​ size = 3 cursor = 5 -> 2 remove = 5 -------------------- 0 1 .. 2023. 1. 11.