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
33 changes: 32 additions & 1 deletion week2/2. 올바른 괄호/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@
2. 올바른 괄호
https://programmers.co.kr/learn/courses/30/lessons/12909
*/
public class Solution {
import java.util.HashMap;
import java.util.Map;

public class Solution2_6 {
public static void main(String[] args) {
String[][] clothes = { { "yellow_hat", "headgear" }, { "blue_sunglasses", "eyewear" },
{ "green_turban", "headgear" } };

System.out.println(solution(clothes));
}

public static int solution(String[][] clothes) {
int answer = 1;

Map<String, Integer> cloteshMap = new HashMap<>();

for (String[] cloth : clothes) {

cloteshMap.put(cloth[1], cloteshMap.getOrDefault(cloth[1], 0) + 1);

}

for (Map.Entry<String, Integer> cloth : cloteshMap.entrySet()) {

answer *= (cloth.getValue() + 1);

}

answer--;

return answer;

}
}
7 changes: 0 additions & 7 deletions week2/5. 다리를 지나는 트럭/Solution.java

This file was deleted.

59 changes: 59 additions & 0 deletions week2/5. 다리를 지나는 트럭/Solution2_5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import java.util.*;

/*
5. 다리를 지나는 트럭
https://programmers.co.kr/learn/courses/30/lessons/42583
*/
public class Solution2_5 {

public static void main(String[] args) {

int bridge_weight = 100;
int bridge_length = 100;
int[] truck_weights = { 10 };

System.out.println(solution(bridge_length, bridge_weight, truck_weights));
}

public static int solution(int bridge_length, int weight, int[] truck_weights) {
Queue<Truck> waiting = new LinkedList<>();
Queue<Truck> bridge = new LinkedList<>();

for (int i = 0; i < truck_weights.length; ++i) {
waiting.offer(new Truck(truck_weights[i], 0));
}

int time = 0;
int totalWeight = 0;
while (!waiting.isEmpty() || !bridge.isEmpty()) {
time++;
if (!bridge.isEmpty()) {
Truck t = bridge.peek();
if (time - t.entry >= bridge_length) {
totalWeight -= t.weight;
bridge.poll();
}
}

if (!waiting.isEmpty()) {
if (totalWeight + waiting.peek().weight <= weight) {
Truck t = waiting.poll();
totalWeight += t.weight;

bridge.offer(new Truck(t.weight, time));
}
}
}
return time;
}
}

class Truck {
int weight;
int entry;

Truck(int weight, int entry) {
this.weight = weight;
this.entry = entry;
}
}
7 changes: 0 additions & 7 deletions week2/6. 위장/Solution.java

This file was deleted.

38 changes: 38 additions & 0 deletions week2/6. 위장/Solution2_6.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
6. 위장
https://programmers.co.kr/learn/courses/30/lessons/42578
*/
import java.util.HashMap;
import java.util.Map;

public class Solution2_6 {
public static void main(String[] args) {
String[][] clothes = { { "yellow_hat", "headgear" }, { "blue_sunglasses", "eyewear" },
{ "green_turban", "headgear" } };

System.out.println(solution(clothes));
}

public static int solution(String[][] clothes) {
int answer = 1;

Map<String, Integer> cloteshMap = new HashMap<>();

for (String[] cloth : clothes) {

cloteshMap.put(cloth[1], cloteshMap.getOrDefault(cloth[1], 0) + 1);

}

for (Map.Entry<String, Integer> cloth : cloteshMap.entrySet()) {

answer *= (cloth.getValue() + 1);

}

answer--;

return answer;

}
}