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

public class bj_1620_나는야포켓몬마스터이다솜 {
public static void main(String[] args) {

// 참고사항) 배열을 돌며 찾았더니 시간초과. 백만은 무리.

Scanner sc = new Scanner(System.in);

int N = sc.nextInt(); // 포켓몬 보유 수
int M = sc.nextInt(); // 맞춰야 하는 수

HashMap<String, Integer> findidx = new HashMap<>(); // 포켓몬 인덱스 출력
HashMap<Integer, String> findpk = new HashMap<>(); // 포켓몬 출력


for(int i=1; i<=N; i++) {

String monster = sc.next();
findidx.put(monster, i); // 인덱스저장
findpk.put(i, monster); // 포켓몬저장
}

StringBuilder sb = new StringBuilder();

for(int i=0; i<M; i++) {
String word = sc.next();

if(word.charAt(0)>='1' && word.charAt(0) <='9') {
// 만약 숫자면 해당 포켓몬 이름 출력
int idx = Integer.parseInt(word);
sb.append(findpk.get(idx));
}else {
// 포켓몬이면 해당 인덱스 출력
sb.append(findidx.get(word));
}
sb.append("\n");
}
System.out.println(sb);
}
}
35 changes: 35 additions & 0 deletions 0503/BOJ/P1676/P1676_yu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.util.Scanner;

public class bj_1676_팩토리얼0의개수 {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int N = sc.nextInt();

int cnt2 = 0;
int cnt5 = 0;

// 2*5 쌍의 결과가 0이 나오므로 쌍 개수가 답이 됨

for(int i=1; i<=N; i++) {

int num = i;

while(num % 2 == 0) {
cnt2++;
num /= 2;
}

while(num% 5 == 0) {
cnt5++;
num /= 5;
}
}



System.out.println(Math.min(cnt2, cnt5));
}

}
44 changes: 44 additions & 0 deletions 0503/Programmers/Lv1/Lv1_yu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class lv1_로또의최고순위와최저순위 {
public static void main(String[] args) {

int[] lottos = { 44, 1, 0, 0, 31, 25 };
int[] win_nums = { 31, 10, 45, 1, 6, 19 };

//

List<Integer> win = new ArrayList<>();

for (int i = 0; i < win_nums.length; i++) {
win.add(win_nums[i]);
}

int[] rank = { 6, 6, 5, 4, 3, 2, 1 };

int zerocnt = 0;
int same = 0;

for (int i = 0; i < lottos.length; i++) {

if (lottos[i] == 0) {
zerocnt++;
}

if (win.contains(lottos[i])) {
same++;
}
}

int[] answer = new int[2];

answer[0] = rank[same + zerocnt];
answer[1] = rank[same];

System.out.println(Arrays.toString(answer));

}

}
38 changes: 38 additions & 0 deletions 0503/Programmers/Lv3/Lv3_yu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class lv3_숫자게임 {
public static void main(String[] args) {

int[] A = { 5, 1, 3, 7 };
int[] B = { 2, 2, 6, 8 };
int answer = 0;
//

// 질 땐 크게 지고, 이길 땐 비슷하게 이기자~

Arrays.sort(A);
Arrays.sort(B);

Deque<Integer> game = new ArrayDeque<>();

int n = A.length;

for (int i = 0; i < n; i++) {
game.add(B[i]);
}


for (int i = n - 1; i >= 0; i--) {

if (A[i] >= game.peekLast()) {
game.pollFirst();
} else {
game.pollLast();
answer++;
}
}
System.out.println(answer);
}
}