diff --git "a/week2/2. \354\230\254\353\260\224\353\245\270 \352\264\204\355\230\270/Solution.java" "b/week2/2. \354\230\254\353\260\224\353\245\270 \352\264\204\355\230\270/Solution.java" index 2150163..f11caa7 100644 --- "a/week2/2. \354\230\254\353\260\224\353\245\270 \352\264\204\355\230\270/Solution.java" +++ "b/week2/2. \354\230\254\353\260\224\353\245\270 \352\264\204\355\230\270/Solution.java" @@ -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 cloteshMap = new HashMap<>(); + + for (String[] cloth : clothes) { + + cloteshMap.put(cloth[1], cloteshMap.getOrDefault(cloth[1], 0) + 1); + + } + + for (Map.Entry cloth : cloteshMap.entrySet()) { + + answer *= (cloth.getValue() + 1); + + } + + answer--; + + return answer; + + } } \ No newline at end of file diff --git "a/week2/5. \353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255/Solution.java" "b/week2/5. \353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255/Solution.java" deleted file mode 100644 index 9c18d9a..0000000 --- "a/week2/5. \353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255/Solution.java" +++ /dev/null @@ -1,7 +0,0 @@ -/* - 5. 다리를 지나는 트럭 - https://programmers.co.kr/learn/courses/30/lessons/42583 -*/ -public class Solution { - -} \ No newline at end of file diff --git "a/week2/5. \353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255/Solution2_5.java" "b/week2/5. \353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255/Solution2_5.java" new file mode 100644 index 0000000..a996d22 --- /dev/null +++ "b/week2/5. \353\213\244\353\246\254\353\245\274 \354\247\200\353\202\230\353\212\224 \355\212\270\353\237\255/Solution2_5.java" @@ -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 waiting = new LinkedList<>(); + Queue 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; + } +} \ No newline at end of file diff --git "a/week2/6. \354\234\204\354\236\245/Solution.java" "b/week2/6. \354\234\204\354\236\245/Solution.java" deleted file mode 100644 index 7361a04..0000000 --- "a/week2/6. \354\234\204\354\236\245/Solution.java" +++ /dev/null @@ -1,7 +0,0 @@ -/* - 7. 전화번호 목록 - https://programmers.co.kr/learn/courses/30/lessons/42577 -*/ -public class Solution { - -} \ No newline at end of file diff --git "a/week2/6. \354\234\204\354\236\245/Solution2_6.java" "b/week2/6. \354\234\204\354\236\245/Solution2_6.java" new file mode 100644 index 0000000..80d5156 --- /dev/null +++ "b/week2/6. \354\234\204\354\236\245/Solution2_6.java" @@ -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 cloteshMap = new HashMap<>(); + + for (String[] cloth : clothes) { + + cloteshMap.put(cloth[1], cloteshMap.getOrDefault(cloth[1], 0) + 1); + + } + + for (Map.Entry cloth : cloteshMap.entrySet()) { + + answer *= (cloth.getValue() + 1); + + } + + answer--; + + return answer; + + } +} \ No newline at end of file