diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no1.java b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no1.java new file mode 100644 index 0000000..2b0e920 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no1.java @@ -0,0 +1,65 @@ +package Today_22_05_24; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class backJoon_greedy_no1 { + + static int answer = -1; + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String n = br.readLine(); + + + + String str = String.valueOf(n); + + boolean[]visited = new boolean[str.length()]; + + + dfs(visited,str,"",0); + + System.out.println(String.valueOf(answer)); + + } + + static boolean check(String now) { + + int a = Integer.parseInt(now); + + if(a%30==0) return true; + else return false; + + + + } + + static void dfs(boolean[]visited,String str,String now,int count) { + + + if(count==str.length()) { + if(check(now)) { + answer = Math.max(answer, Integer.parseInt(now)); + } + return; + } + + for(int i=0;i=25) { + money -= 25; + a++; + } + else if(money>=10) { + money -= 10; + b++; + } + else if(money>=5) { + money -=5; + c++; + } + else { + money -= 1; + d++; + + } + + if(money<=0) break; + + } + + + System.out.println(a+" "+b+" "+c+" "+d); + + } + + + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no3.java b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no3.java new file mode 100644 index 0000000..7d6812a --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no3.java @@ -0,0 +1,33 @@ +package Today_22_05_24; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class backJoon_greedy_no3 { + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] input = br.readLine().split(""); + + int i = 0; + for(String checkA : input) { + if(i == 0 && checkA.equals("U")) i++; + if((i == 1 || i == 3) && checkA.equals("C")) i++; + if(i == 2 && checkA.equals("P")) i++; + } + if(i==4) { + System.out.println("I love UCPC"); + }else { + System.out.println("I hate UCPC"); + } + + + } + + + + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no4.java b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no4.java new file mode 100644 index 0000000..7e12d23 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no4.java @@ -0,0 +1,58 @@ +package Today_22_05_24; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class backJoon_greedy_no4 { + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int answer = 0; + + int n = Integer.parseInt(br.readLine()); + + String s = br.readLine(); + + Integer []crain = new Integer[n]; + + for(int i=0;i q = new PriorityQueue<>(Collections.reverseOrder()); + + for(int i=0;icrain[0]) answer = -1; + else { + + while(!q.isEmpty()) { + + answer++; + + for(int i=0;i= q.peek()) q.poll(); + if(q.isEmpty()) break; + + } + + if(q.isEmpty()) break; + + } + } + + + System.out.println(answer); + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no5.java b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no5.java new file mode 100644 index 0000000..3ba6717 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/backJoon_greedy_no5.java @@ -0,0 +1,18 @@ +package Today_22_05_24; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class backJoon_greedy_no5 { + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_1.java b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_1.java new file mode 100644 index 0000000..c3328b3 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_1.java @@ -0,0 +1,54 @@ +package Today_22_05_24; + +public class programmer_lv_2_no_1 { + + public static void main(String[] args) { + + + + String s = "aabbaccc"; + + int answer = Integer.MAX_VALUE; + + + for(int i=1;i<=s.length()/2;i++) { + + String result =""; + String next = ""; + String now = ""; + int hit = 1; + + for(int j=0;j<=s.length()/i;j++) { + + int start = i * j; + int end = i * ( j + 1 ) > s.length() ? s.length():i*(j+1) ; + + next = s.substring(start,end); + + if(now.equals(next)) { + hit++; + }else { + + result += processHit(hit) + now; + hit = 1; + } + now = next; + + + } + result += processHit(hit) + now; + + System.out.println(result + " : " + result.length() + " 개"); + + answer = Math.min(answer, result.length()); + } + + System.out.println("답 :" + answer+" 개 "); + + + } + static String processHit(int hit) { + return hit>1 ? String.valueOf(hit) : ""; + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_2.java b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_2.java new file mode 100644 index 0000000..20739be --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_2.java @@ -0,0 +1,56 @@ +package Today_22_05_24; + +import java.util.Queue; +import java.util.LinkedList; +import java.util.ArrayList; + +public class programmer_lv_2_no_2 { + + public static void main(String[] args) { + + int [] progresses = {95, 90, 99, 99, 80, 99}; + + int [] speeds = {1, 1, 1, 1, 1, 1}; + + Queue q = new LinkedList<>(); + + for(int i=0;i answerList = new ArrayList<>(); + + while(!q.isEmpty()) { + + int a = q.poll(); + + int answerInt = 1; + + while(!q.isEmpty() && a>= q.peek()) { + + answerInt++; + q.poll(); + } + + answerList.add(answerInt); + + } + + System.out.println(answerList); + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_3.java b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_3.java new file mode 100644 index 0000000..edb7701 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_24/programmer_lv_2_no_3.java @@ -0,0 +1,84 @@ +package Today_22_05_24; + + +import java.util.ArrayList; +import java.util.Collections; + +public class programmer_lv_2_no_3 { + + static ArrayList answer = new ArrayList<>(); + static int[] ryan; + static int[] apeach; + static int N; + static int max = Integer.MIN_VALUE; + + + public static void main(String[] args) { + + int []info = {0,0,0,0,0,0,0,0,3,4,3}; + + int n = 10; + + apeach = info.clone(); + + ryan = new int[11]; + N = n; + apeach = info.clone(); + dfs(0, 0); + + Collections.sort(answer,(o1,o2)->{ + + + for(int i=apeach.length-1;i>-1;i--) { + if(o1[i]!=o2[i]) return o2[i]-o1[i]; + } + + + return 0; + }); + + for(int i : answer.get(0))System.out.print(i+","); + + } + + static void dfs(int s, int l) { + + if(l==N) { + int r = 0; + int a = 0; + + for(int i=0;ia) { + int diff = r - a; + if(diff>max) { + max = diff; + answer.clear(); + answer.add(ryan.clone()); + }else if(diff==max) { + answer.add(ryan.clone()); + } + + } + + + } + + else { + + for(int i=s;i 2 -> 3 -> 8 -> 6 -> 5 -> 4 -> 7 -> - } - static String bfs(int start, int[][] graph, boolean[] visited) { - // 탐색 순서를 출력하기 위한 용도 - StringBuilder sb = new StringBuilder(); - // BFS에 사용할 큐를 생성해줍니다. - Queue q = new LinkedList(); - // 큐에 BFS를 시작 할 노드 번호를 넣어줍니다. - q.offer(start); - // 시작노드 방문처리 - visited[start] = true; - // 큐가 빌 때까지 반복 - while(!q.isEmpty()) { - int nodeIndex = q.poll(); - sb.append(nodeIndex + " -> "); - //큐에서 꺼낸 노드와 연결된 노드들 체크 - for(int i=0; i q = new LinkedList<>(); + + q.add(new int[] {0,0}); + + int[][]move = {{0,1},{1,0},{0,-1},{-1,0}}; + + while(!q.isEmpty()) { + + int[]cur = q.poll(); + + int i = cur[0]; + int j = cur[1]; + + + + for(int d=0;d<4;d++) { + + int newI = i + move[d][0]; + int newJ = j + move[d][1]; + + + if(newI<0||newJ<0||maps.length-1