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
29 changes: 29 additions & 0 deletions 0503/BOJ/P1620/P1620_ko.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main_P1620 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt(); // 포켓몬 수
int M = sc.nextInt(); // 문제 수
Map<String, String> nameMap = new HashMap<>(); // 번호에 해당하는 스트링
Map<String, String> numMap = new HashMap<>(); // 이름에 해당하는 번호
for (int i = 1; i <= N; i++) {
String name = sc.next();
nameMap.put(String.valueOf(i), name);
numMap.put(name, String.valueOf(i));
}

for (int i = 0; i < M; i++) {
String q = sc.next();
if (nameMap.containsKey(q)) // 번호면 이름 이름이면 번호
System.out.println(nameMap.get(q));
else
System.out.println(numMap.get(q));
}

}

}
20 changes: 20 additions & 0 deletions 0503/BOJ/P1676/P1676_ko.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.Scanner;

public class Main_P1676 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); // 숫자 입력
int cnt = 0;
int np;
for (int i = n; i >= 5; i--) { // 5개수로 0개수 세기
np = i;
while (np % 5 == 0) {
cnt++;
np /= 5;
}
}
System.out.print(cnt);
}

}
52 changes: 52 additions & 0 deletions 0503/BOJ/P1697/P1697_ko.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main_P1697 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt(); // 수빈
int K = sc.nextInt(); // 동생
System.out.print(bfs(N, K));
}

static int bfs(int N, int K) {
boolean[] visit = new boolean[100001]; // 0~100000 갈 수 있음
Queue<Integer> q = new LinkedList<>();
int next, now;
int ret = 0; // 0초로 초기화

q.add(N); // 시작 위치 방문
visit[N] = true;
while (N != K) { // 첫 값 같은 자리인지 확인
int size = q.size();
for (int i = 0; i < size; i++) { // 사이즈로 묶기
now = q.poll();
for (int j = 0; j < 3; j++) {
if (j == 0)
next = now - 1;
else if (j == 1)
next = now + 1;
else
next = now * 2;

if (next < 0 || next > 100000 || visit[next]) // 다음 값 갈 수 있는지
continue;

if (next == K) // 찾았다면 끝
return ++ret; // 다음 번에 갈 수 있으므로 +1

q.add(next);
visit[next] = true; // 갈 수 있으면 방문처리
}
}

ret++; // 깊이
}

return ret;

}

}