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
34 changes: 34 additions & 0 deletions 0503/BOJ/P1620/P1620_kim.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class P1620_kim {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int m = sc.nextInt();
int n = sc.nextInt();
List<String> poket = new ArrayList<>();
Map<String, Integer> map = new HashMap<>();
for(int i = 0; i < m; i++) {
String poketmon = sc.next();
poket.add(poketmon); // 포켓몬 저장
map.put(poketmon, i); // 포켓몬 이름과 번호를 매핑해서 이름으로 번호를 찾기 쉽게 한다.
}
for(int i = 0; i < n; i++) {
String a = sc.next();
if(a.charAt(0)-'0' >= 0 && a.charAt(0)-'0' <= 9) {
sb.append(poket.get(Integer.parseInt(a)-1)).append("\n"); // 인덱스가 0부터 시작이라 -1 해주었다.

}else {
sb.append(map.get(a)+1).append("\n"); // 인덱스가 0부터 시작이라 +1 해주었다.
}
}
System.out.println(sb.toString());

}

}
15 changes: 15 additions & 0 deletions 0503/BOJ/P1676/P1676_kim.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


import java.util.Scanner;

public class baekjoon_P1676_팩토리얼 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
// 25의 배수이면 0이 2개 더 붙어서 n/25 , 125의 배수이면 0이 3개 더 붙어서 n/125 해준다!
int ans = (n/5)+(n/25)+(n/125);
System.out.println(ans);

}

}
49 changes: 49 additions & 0 deletions 0503/BOJ/P1697/P1697_kim.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@


import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class baekjoon_P1697_숨바꼭질 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
Queue<Integer> queue = new LinkedList<>();
boolean[] visited = new boolean[100001]; // 방문처리!
queue.add(n);
visited[n] = true;
int ans = 0;
if(n > k) { // 수빈이가 동생보다 앞에 있다면 수빈이 위치 - 동생 위치
ans = n-k;
}else if( n == k) { // 둘의 위치가 같다면 0
ans = 0;
}else {
out:while(true) {
int size = queue.size();
for(int i = 0; i < size; i++) {
int num = queue.poll();
if(num == k) { // 수빈이 위치가 동생 위치랑 같아지면 멈춤
break out;
}
// 아직 다음 위치를 방문하지 않았을 때만 queue에 넣어주고 방문처리 해준다!!!
if(num+1 <= 100000 && !visited[num+1]) {
queue.add(num+1);
visited[num+1] = true;
}

if( num-1 >= 0 && !visited[num-1]) {
queue.add(num-1);
visited[num-1] = true;
}
if( num*2 <= 100000 && !visited[num*2]) {
queue.add(num*2);
visited[num*2] = true;
}
}
ans++;
}
}
System.out.println(ans);
}
}