diff --git "a/KHJ_Root/\353\260\261\354\244\200\353\254\270\354\240\234/\353\252\250\354\235\214\354\202\254\354\240\204.java" "b/KHJ_Root/\353\260\261\354\244\200\353\254\270\354\240\234/\353\252\250\354\235\214\354\202\254\354\240\204.java" new file mode 100644 index 0000000..06d2dca --- /dev/null +++ "b/KHJ_Root/\353\260\261\354\244\200\353\254\270\354\240\234/\353\252\250\354\235\214\354\202\254\354\240\204.java" @@ -0,0 +1,22 @@ +class Solution { + public int solution(String word) { + // 문자와 인덱스 매핑: A=0, E=1, I=2, O=3, U=4 + char[] vowels = {'A', 'E', 'I', 'O', 'U'}; + int[] weights = {781, 156, 31, 6, 1}; // 각 자리별 가중치: 5^4, 5^3, 5^2, 5^1, 5^0 + + int answer = 0; + for (int i = 0; i < word.length(); i++) { + char c = word.charAt(i); + // 현재 문자의 인덱스 찾기 + for (int j = 0; j < vowels.length; j++) { + if (c == vowels[j]) { + // 현재 자리에서 이전 문자들의 단어 수 + 현재 단어 + answer += j * weights[i] + 1; + break; + } + } + } + + return answer; + } +} diff --git "a/KHJ_Root/\353\260\261\354\244\200\353\254\270\354\240\234/\353\260\261\354\244\2001761\353\262\210(\354\240\225\354\240\220\353\223\244\354\235\230\352\261\260\353\246\254).java" "b/KHJ_Root/\353\260\261\354\244\200\353\254\270\354\240\234/\353\260\261\354\244\2001761\353\262\210(\354\240\225\354\240\220\353\223\244\354\235\230\352\261\260\353\246\254).java" new file mode 100644 index 0000000..7853fea --- /dev/null +++ "b/KHJ_Root/\353\260\261\354\244\200\353\254\270\354\240\234/\353\260\261\354\244\2001761\353\262\210(\354\240\225\354\240\220\353\223\244\354\235\230\352\261\260\353\246\254).java" @@ -0,0 +1,82 @@ +import java.io.*; +import java.util.*; + +class Edge { + int vertex; + int weight; + + Edge(int vertex, int weight) { + this.vertex = vertex; + this.weight = weight; + } +} + +public class Main { + static ArrayList[] graph; + static int N; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + // 정점 수 입력 + N = Integer.parseInt(br.readLine()); + // 인접 리스트 초기화 + graph = new ArrayList[N + 1]; + for (int i = 1; i <= N; i++) { + graph[i] = new ArrayList<>(); + } + + // 간선 정보 입력 (N-1개) + for (int i = 0; i < N - 1; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int w = Integer.parseInt(st.nextToken()); + graph[a].add(new Edge(b, w)); + graph[b].add(new Edge(a, w)); // 무방향 트리 + } + + // 쿼리 수 입력 + int M = Integer.parseInt(br.readLine()); + // 쿼리 처리 + for (int i = 0; i < M; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int u = Integer.parseInt(st.nextToken()); + int v = Integer.parseInt(st.nextToken()); + int distance = bfs(u, v); + bw.write(distance + "\n"); + } + + bw.flush(); + bw.close(); + br.close(); + } + + // BFS로 두 정점 간 거리 계산 + static int bfs(int start, int end) { + int[] dist = new int[N + 1]; + Arrays.fill(dist, -1); // -1: 미방문 + dist[start] = 0; // 시작점 거리 0 + Queue queue = new LinkedList<>(); + queue.add(start); + + while (!queue.isEmpty()) { + int curr = queue.poll(); + if (curr == end) { // 목표 정점 도달 + return dist[curr]; + } + + for (Edge edge : graph[curr]) { + int next = edge.vertex; + int weight = edge.weight; + if (dist[next] == -1) { // 미방문 정점 + dist[next] = dist[curr] + weight; + queue.add(next); + } + } + } + + return -1; // 도달 불가능 (트리이므로 발생하지 않음) + } +} diff --git "a/KHJ_Root/\353\260\261\354\244\200\353\254\270\354\240\234/\354\202\274\354\264\235\354\202\254.java" "b/KHJ_Root/\353\260\261\354\244\200\353\254\270\354\240\234/\354\202\274\354\264\235\354\202\254.java" new file mode 100644 index 0000000..8972270 --- /dev/null +++ "b/KHJ_Root/\353\260\261\354\244\200\353\254\270\354\240\234/\354\202\274\354\264\235\354\202\254.java" @@ -0,0 +1,19 @@ +class Solution { + public int solution(int[] number) { + int n = number.length; + int count = 0; + + // 세 학생의 인덱스 i, j, k 선택 (i < j < k) + for (int i = 0; i < n - 2; i++) { + for (int j = i + 1; j < n - 1; j++) { + for (int k = j + 1; k < n; k++) { + if (number[i] + number[j] + number[k] == 0) { + count++; + } + } + } + } + + return count; + } +}