-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from leetaggg/main
이태호 / 10월 4주차 / 목
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |