Skip to content

20230926 이기진 2문제 #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions 이기진/0926week28/알파벳블록.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Stack;
import java.util.StringTokenizer;

public class 알파벳블록 {

public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bf.readLine());
StringTokenizer st;
Deque<Character> deque = new ArrayDeque<>();
Stack<Integer> stack = new Stack<>();
for(int i = 0; i < n; i++){
st = new StringTokenizer(bf.readLine());
if(st.countTokens() == 1){
if(!stack.empty()) {
if(stack.pop() == 1) {
deque.pollLast();
}
else {
deque.pollFirst();
}
}
}
else{
stack.push(Integer.parseInt(st.nextToken()));
char c = st.nextToken().charAt(0);
if(stack.peek() == 1){
deque.addLast(c);
}
else{
deque.addFirst(c);
}
}
}
StringBuilder sb = new StringBuilder();

if(deque.size() == 0){
sb.append(0);
}
else{
while(!deque.isEmpty()) {
sb.append(deque.pollFirst());
}
}
System.out.println(sb);
}

}
72 changes: 72 additions & 0 deletions 이기진/0926week28/어드벤쳐게임.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class 어드벤쳐게임 {
static ArrayList<Integer>[] linkRoom;
static char[] rType;
static int[] mInfo;
static int N;
static boolean flag;
static boolean[] visited;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
StringBuilder ans = new StringBuilder();
N = 0;
while((N = Integer.parseInt(br.readLine())) != 0) {
rType = new char[N+1];
linkRoom = new ArrayList[N+1];
mInfo = new int[N+1];
visited = new boolean[N+1];
for(int i=1; i<=N; i++) {
st = new StringTokenizer(br.readLine());
rType[i] = st.nextToken().charAt(0);
mInfo[i] = Integer.parseInt(st.nextToken());
linkRoom[i] = new ArrayList<>();
int roomNum = 0;
while((roomNum = Integer.parseInt(st.nextToken())) != 0) {
linkRoom[i].add(roomNum);
}
}
flag = false;
goDfs(1, 0);
if(flag) {
System.out.println("Yes");
}
else
System.out.println("No");
}
}

private static void goDfs(int room, int money) {
if(flag) return;
if(room == N) {
flag = true;
return;
}

for(int i =0; i<linkRoom[room].size(); i++) {

int rNum = linkRoom[room].get(i);

if(visited[rNum]) continue;
if(rType[rNum] == 'L') {
if(mInfo[rNum] > money) {
money = mInfo[rNum];
}
} else if(rType[rNum] == 'T') {
if(mInfo[rNum] <= money) {
money -= mInfo[rNum];
} else {
return;
}
}
visited[rNum] = true;
goDfs(rNum, money);
visited[rNum] = false;
}
return;
}
}