목록Study/Problem Solving (163)
전공공부
설명 이번 문제는 쉽게 풀지 못해서 이전에 풀었던 히스토리를 가지고 풀었다. 우선 스택 수열때 처럼 카운팅 하는 방식을 버리고 애초에 괄호의 닫힌 괄호를 처음 push 할 때 넣어버려서 닫힌 괄호가 들어 올 때 검증 체크를 진행하고 이에 따라서, 괄호의 값을 넣어준다. 코드 package Data_Structure; import java.util.*; import java.io.*; public class BOJ_2504 { public static void main(String[] args) throws Exception{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = in.readLine();..
설명 Stack에 대해서 크게 이해를 하고 있지 않아도 사실상 구현 문제에 가까운 느낌이였다. 반복문 셋팅을 잘 못하고 else 문 처리를 잘 못 해서 시간을 많이 잡아 먹은 문제다. 코드 package Data_Structure; import java.util.*; import java.io.*; public class BOJ_1874 { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); Stack st = new Stack(); int top = 0; StringBuffer sb = new StringBuffer(); for(int i = 0; ..
설명 코테 1번에 나올 법한 쉬운 문제 코드 package Data_Structure; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class BOJ_14425 { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); Map map = new HashMap(); for(int i = 0; i < N; i++){ String str = sc.next(); map.put(str,i+1); } int ans = 0; fo..
설명 사실상 구현 문제다. 코드 package Data_Structure; import java.io.*; import java.util.*; public class BOJ_1620 { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); Map map = new LinkedHashMap(); Map numMap = new LinkedHashMap(); for(int i = 0; i < N; i++){ String str = sc.next(); map.put(str,i+1); numMap.put(i+1,str); ..
설명 자료 구조 섹션은 구현 문제가 많은 것 같다. 인덱스와 크기 값을 저장하고 크기값에 따라서 내림차순 정렬 한 후 그 후 내가 보는 순서가 맞을때 하나씩 빼서 구현한 것 같다. 코드 package Data_Structure; import java.util.*; public class BOJ_1966 { static class Data implements Comparable{ int idx; int weight; public Data (int idx, int weight){ this.idx = idx; this.weight = weight; } @Override public int compareTo(Data o) { if(o.weight > this.weight){ return 1; }else if(o..
설명 사실 Deque의 사용을 생각해내는 것 보다 이것을 제출할때 메모리 초과 등의 오류를 잡는 것이 힘들다. 코드 package Data_Structure; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class BOJ_2346 { static class Balloon { int idx; // 풍선 번호 int value; // 적혀있는 값 public Balloon(int idx, int value) { this.idx=idx; this.value=value; } } public static void main(String[] args) throws Exception{ Buffered..
설명 후위 표기식이 어떻게 동작하는지만 알면 풀기 쉽다. 4 7 2 + - 이렇게 있으면 이것은 2 + 7 하고 4 - 9 이것과 같다. 이런식으로 풀이를 해나가기 위해서는 stack을 사용해서 풀면된다. LIFO이니깐 그리고, 뺄 때 순서 바꿔서 빼는 것을 주의하면 된다. 코드 package Data_Structure; import java.io.*; import java.util.*; public class BOJ_1935 { public static void main(String[] args) throws Exception{ Stack st = new Stack(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); ..
설명 사실 이 풀이는 좋은 풀이법은 아니다. 아예 API를 쓸 거면 Deque를 사용하면 되는데 이상하게 List를 사용해서 풀었기 때문이다. 아니면 아예 int[]로 직접 구현해서 푸는 것도 자료구조를 익히는데 좋은 방법이 될 것 같다. 코드 package Data_Structure; import java.io.*; import java.util.*; public class BOJ_10866 { public static void main(String[] args) throws Exception{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tk = new StringTokenizer(in..