Skip to content
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
22 changes: 22 additions & 0 deletions KHJ_Root/백준문제/모음사전.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
82 changes: 82 additions & 0 deletions KHJ_Root/백준문제/백준1761번(정점들의거리).java
Original file line number Diff line number Diff line change
@@ -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<Edge>[] 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<Integer> 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; // 도달 불가능 (트리이므로 발생하지 않음)
}
}
19 changes: 19 additions & 0 deletions KHJ_Root/백준문제/삼총사.java
Original file line number Diff line number Diff line change
@@ -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;
}
}