Skip to content
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

이선주 / 10월 4주차 / 월 #294

Open
wants to merge 2 commits 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
53 changes: 53 additions & 0 deletions LeeSunJu/boj/boj10159.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.io.*;
import java.util.*;

public class boj10159 {
static int N, M;
static int[] cnt;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

N = Integer.parseInt(br.readLine());
M = Integer.parseInt(br.readLine());
cnt = new int[N + 1];

ArrayList<ArrayList<Integer>> in = new ArrayList<>(); // 진입
ArrayList<ArrayList<Integer>> out = new ArrayList<>(); // 진출
for (int i = 0; i <= N; i++) {
in.add(new ArrayList<>());
out.add(new ArrayList<>());
}

StringTokenizer st;
for (int i = 0; i < M; i++) {
st = new StringTokenizer(br.readLine(), " ");
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());

in.get(a).add(b);
out.get(b).add(a);
}

for (int i = 1; i <= N; i++) {
dfs(i, i, in, new boolean[N + 1]);
dfs(i, i, out, new boolean[N + 1]);
}


StringBuilder sb = new StringBuilder();
for (int i = 1; i <= N; i++) {
sb.append(N - cnt[i] - 1).append("\n");
}
System.out.print(sb.toString());
}

private static void dfs(int i, int start, ArrayList<ArrayList<Integer>> list, boolean[] visited) {
visited[i] = true;
for (int n : list.get(i)) {
if (!visited[n]) {
cnt[start]++;
dfs(n, start, list, visited);
}
}
}
}
34 changes: 34 additions & 0 deletions LeeSunJu/boj/boj12919.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import java.io.*;

public class boj12919 {

static String S, T;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

S = br.readLine();
T = br.readLine();

System.out.println(solve(T));
}

private static int solve(String t) {
if (t.length() == S.length()) {
if (t.equals(S)) {
return 1;
}
return 0;
}

int result = 0;
if (t.charAt(0) == 'B') {
result += solve(new StringBuilder(t.substring(1)).reverse().toString());
}

if (t.charAt(t.length() - 1) == 'A') {
result += solve(t.substring(0, t.length() - 1));
}

return result == 0 ? 0 : 1;
}
}