Skip to content

Commit

Permalink
Merge pull request #304 from leetaggg/main
Browse files Browse the repository at this point in the history
이태호 / 10월 4주차 / 목
  • Loading branch information
leetaggg authored Oct 30, 2023
2 parents 09542e4 + 38dc2f1 commit 42814c7
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
37 changes: 37 additions & 0 deletions LeeTaeHo/boj/boj16120.java
Original file line number Diff line number Diff line change
@@ -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<Character> 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';
}
}
43 changes: 43 additions & 0 deletions LeeTaeHo/boj/boj2467.java
Original file line number Diff line number Diff line change
@@ -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]);
}
}

0 comments on commit 42814c7

Please sign in to comment.