diff --git a/LeeTaeHo/boj/boj16120.java b/LeeTaeHo/boj/boj16120.java new file mode 100644 index 00000000..529a5ff6 --- /dev/null +++ b/LeeTaeHo/boj/boj16120.java @@ -0,0 +1,37 @@ +import java.io.*; +import java.util.*; + +public class boj16120 { + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + char[] ppap = br.readLine().toCharArray(); + if (isPPAP(ppap)) { + System.out.println("PPAP"); + } else { + System.out.println("NP"); + } + } + + static boolean isPPAP(char[] ppap) { + if (ppap.length < 4) { + return ppap.length == 1 && ppap[0] == 'P'; + } + + Stack s = new Stack<>(); + + for (int i = 0; i < 3; i++) { + s.push(ppap[i]); + } + + for (int i = 3; i < ppap.length; i++) { + if (s.size() >= 3 && ppap[i] == 'P' && s.elementAt(s.size() - 1) == 'A' && s.elementAt(s.size() - 2) == 'P' && s.elementAt(s.size() - 3) == 'P') { + for (int j = 0; j < 3; j++) { + s.pop(); + } + } + s.push(ppap[i]); + } + + return s.size() == 1 && s.peek() == 'P'; + } +} \ No newline at end of file diff --git a/LeeTaeHo/boj/boj2467.java b/LeeTaeHo/boj/boj2467.java new file mode 100644 index 00000000..30597849 --- /dev/null +++ b/LeeTaeHo/boj/boj2467.java @@ -0,0 +1,43 @@ +import java.io.*; +import java.util.*; + +public class boj2467 { + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int n = Integer.parseInt(br.readLine()); + + StringTokenizer st = new StringTokenizer(br.readLine()); + + int[] arr = new int[n]; + + for (int i = 0; i < n; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + + int left = 0; + int right = arr.length - 1; + int sum = 0; + + int resultLeft = 0; + int resultRight = 0; + int minValue = Integer.MAX_VALUE; + + while(left < right){ + sum = arr[left] + arr[right]; + if(Math.abs(minValue) > Math.abs(sum)){ + minValue = sum; + resultLeft = left; + resultRight = right; + } + if(sum == 0){ + break; + }else if(sum < 0){ + left++; + }else{ + right--; + } + } + System.out.println(arr[resultLeft] + " " + arr[resultRight]); + } +}