diff --git a/week11/clean2001/B17837.java b/week11/clean2001/B17837.java index eac6e61..3382f1f 100644 --- a/week11/clean2001/B17837.java +++ b/week11/clean2001/B17837.java @@ -48,6 +48,7 @@ public static void main(String[] args) throws Exception { } } + // 말들이 들어있는 리스트. 인덱스를 1번부터 하기 위해 null을 넣어줌 list.add(null); for(int i=1; i<=K; ++i) { st = new StringTokenizer(br.readLine()); @@ -55,7 +56,7 @@ public static void main(String[] args) throws Exception { int c = Integer.parseInt(st.nextToken()); int d = Integer.parseInt(st.nextToken()); - list.add(new Node(i, d-1, r ,c)); + list.add(new Node(i, d-1, r ,c)); // 리스트에 말을 저장 map[r][c].add(list.get(i)); // 말을 체스판에 놓기 } diff --git a/week12/clean2001/.gitkeep b/week12/clean2001/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/week12/clean2001/B1027.java b/week12/clean2001/B1027.java new file mode 100644 index 0000000..7e9f361 --- /dev/null +++ b/week12/clean2001/B1027.java @@ -0,0 +1,87 @@ +import java.io.*; +import java.util.*; +// 1027. 고층 건물 +class Main { + static int N; + static int[] arr; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + N = Integer.parseInt(br.readLine()); + arr = new int[N]; + + StringTokenizer st = new StringTokenizer(br.readLine()); + for(int i=0; i=0; i--) { // i와 b 건물 사이 + // 직선을 구하기 + double t = tan(i, b, arr[i], arr[b]); + double k = y_meet(i, arr[i], t); + + // i~b 사이에 건물들이 닿는지를 확인 + boolean flag = false; + for(int j=i+1; j 됨 + cnt1++; + } + + } + + // 앞쪽 확인 + int cnt2 = 0; + for(int i=b+1; i 됨 + cnt2++; + } + + } + + + if(ans < cnt1+cnt2) { + ans = cnt1+cnt2; + + } + } + + System.out.println(ans); + + } + + public static double tan(int x1, int x2, int y1, int y2) { + if(x1 == x2) return 0; // 있을 수 없는 경우 + + return (((double)y2-(double)y1) / ((double)x2-(double)x1)); + } + + public static double y_meet(int x1, int y1, double t) { + return (double)y1 - t * (double)x1; + } +} \ No newline at end of file diff --git a/week12/clean2001/B1406.java b/week12/clean2001/B1406.java new file mode 100644 index 0000000..d7830c5 --- /dev/null +++ b/week12/clean2001/B1406.java @@ -0,0 +1,55 @@ +import java.io.*; +import java.util.*; +// 1406. 에디터 +// 스택을 쓰지 않고, 직접 문자열을 고치는 식으로 구현하면 +// substring()과 같은 O(N)인 메소드 때문에 시간초과가 발생합니다. +class Main { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String input = br.readLine(); + + int N = Integer.parseInt(br.readLine()); + Deque st1 = new LinkedList<>(); + Deque st2 = new LinkedList<>(); + + for(int i=0; i st1에 추가 + String ch = st.nextToken(); + st1.addLast(ch); + } else if(cmd.equals("L")) { // 왼쪽으로 이동 -> s1에서 s2로 옮기기 + if(st1.isEmpty()) continue; + st2.addLast(st1.pollLast()); + } else if(cmd.equals("B")) { // 삭제 -> s1하나 삭제 + if(st1.isEmpty()) continue; + st1.removeLast(); + } else if(cmd.equals("D")) { // 오른쪽으로이동 + if(st2.isEmpty()) continue; + st1.addLast(st2.pollLast()); + } + + } + + + StringBuilder sb1 = new StringBuilder(); + while(!st1.isEmpty()) { + sb1.append(st1.pollLast()); + } + StringBuilder sb2 = new StringBuilder(); + while(!st2.isEmpty()) { + sb2.append(st2.pollLast()); + } + + + System.out.println(sb1.reverse().toString() + sb2.toString()); + + } +} \ No newline at end of file