diff --git a/Basic_Of_Algorithm/src/Today22_05_11/bfs.java b/Basic_Of_Algorithm/src/Today_22_05_11/bfs.java similarity index 98% rename from Basic_Of_Algorithm/src/Today22_05_11/bfs.java rename to Basic_Of_Algorithm/src/Today_22_05_11/bfs.java index 1d7af4b..117d37f 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/bfs.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/bfs.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; import java.util.LinkedList; import java.util.Queue; diff --git a/Basic_Of_Algorithm/src/Today22_05_11/bfsAgain.java b/Basic_Of_Algorithm/src/Today_22_05_11/bfsAgain.java similarity index 98% rename from Basic_Of_Algorithm/src/Today22_05_11/bfsAgain.java rename to Basic_Of_Algorithm/src/Today_22_05_11/bfsAgain.java index 0a1800b..bca547d 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/bfsAgain.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/bfsAgain.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; import java.util.LinkedList; import java.util.Queue; diff --git a/Basic_Of_Algorithm/src/Today22_05_11/combi_dfs.java b/Basic_Of_Algorithm/src/Today_22_05_11/combi_dfs.java similarity index 97% rename from Basic_Of_Algorithm/src/Today22_05_11/combi_dfs.java rename to Basic_Of_Algorithm/src/Today_22_05_11/combi_dfs.java index 693874f..4d9802b 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/combi_dfs.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/combi_dfs.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; public class combi_dfs { diff --git a/Basic_Of_Algorithm/src/Today22_05_11/dfs.java b/Basic_Of_Algorithm/src/Today_22_05_11/dfs.java similarity index 97% rename from Basic_Of_Algorithm/src/Today22_05_11/dfs.java rename to Basic_Of_Algorithm/src/Today_22_05_11/dfs.java index 3190a0d..f468513 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/dfs.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/dfs.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; public class dfs { diff --git a/Basic_Of_Algorithm/src/Today22_05_11/test.java b/Basic_Of_Algorithm/src/Today_22_05_11/test.java similarity index 98% rename from Basic_Of_Algorithm/src/Today22_05_11/test.java rename to Basic_Of_Algorithm/src/Today_22_05_11/test.java index d86f3b7..82b89ad 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/test.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/test.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; import java.util.*; diff --git a/Basic_Of_Algorithm/src/Today22_05_11/twoPointer.java b/Basic_Of_Algorithm/src/Today_22_05_11/twoPointer.java similarity index 98% rename from Basic_Of_Algorithm/src/Today22_05_11/twoPointer.java rename to Basic_Of_Algorithm/src/Today_22_05_11/twoPointer.java index 202e7d6..9fc63d5 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/twoPointer.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/twoPointer.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; import java.util.Arrays; diff --git a/Basic_Of_Algorithm/src/Today22_05_11/twoPointerRangeSum.java b/Basic_Of_Algorithm/src/Today_22_05_11/twoPointerRangeSum.java similarity index 96% rename from Basic_Of_Algorithm/src/Today22_05_11/twoPointerRangeSum.java rename to Basic_Of_Algorithm/src/Today_22_05_11/twoPointerRangeSum.java index e515221..802aa0a 100644 --- a/Basic_Of_Algorithm/src/Today22_05_11/twoPointerRangeSum.java +++ b/Basic_Of_Algorithm/src/Today_22_05_11/twoPointerRangeSum.java @@ -1,4 +1,4 @@ -package Today22_05_11; +package Today_22_05_11; import java.util.Arrays; diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/RankingSearch.java b/Basic_Of_Algorithm/src/Today_22_05_12/RankingSearch.java new file mode 100644 index 0000000..df087e1 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/RankingSearch.java @@ -0,0 +1,86 @@ +package Today_22_05_12; + +import java.util.HashMap; +import java.util.ArrayList; +import java.util.Collections; + +public class RankingSearch { + + static HashMap> map = new HashMap<>(); + + + public static void main(String[] args) { + + + String [] info = {"java backend junior pizza 150","python frontend senior chicken 210","python frontend senior chicken 150","cpp backend senior pizza 260","java backend junior chicken 80","python backend senior chicken 50"}; + + String [] query = {"java and backend and junior and pizza 100","python and frontend and senior and chicken 200","cpp and - and senior and pizza 250","- and backend and senior and - 150","- and - and - and chicken 100","- and - and - and - 150"}; + + int[]result = new int[query.length]; + + + for(int i=0;i list = map.get(key); + + int start = 0; + + int end = list.size()-1; + + + while(start<=end) { + + int mid = (start+end)/2; + + if(score<=list.get(mid)) end = mid-1; + else if(score>list.get(mid)) start = mid+1; + + + } + + return list.size()-start; + + + } + + static void dfs(String[]temp,int count,String now) { + + + if(count==4) { + if(!map.containsKey(now)) { + map.put(now, new ArrayList<>()); + } + map.get(now).add(Integer.parseInt(temp[4])); + return; + } + + dfs(temp,count+1,now+"-"); + dfs(temp,count+1,now+temp[count]); + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/apchuck.java b/Basic_Of_Algorithm/src/Today_22_05_12/apchuck.java new file mode 100644 index 0000000..7e9a852 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/apchuck.java @@ -0,0 +1,57 @@ +package Today_22_05_12; + +public class apchuck { + + public static void main(String[] args) { + + String s = "ababcdcdababcdcd"; + + + int answer = Integer.MAX_VALUE; + + + for(int i=1;i<=s.length()/2;i++) { + + + String result = ""; + String now = ""; String next = ""; + int count = 1; + + for(int j=0;j<=s.length()/i;j++) { + + + int start = j*i; + + int end = s.length() > i * (j+1) ? i * (j+1) : s.length(); + + now = next; + + next = s.substring(start,end); + + if(now.equals(next)) { + count++; + }else { + result += check(count) + now; + count = 1; + } + + + + } + + result += check(count) + next; + + System.out.println(result + " -> 갯수 : "+ result.length()); + + answer = Math.min(answer, result.length()); + + } + System.out.println(); + System.out.println("답 : " + answer); + + } + + static String check(int count) { + return count > 1 ? String.valueOf(count) : ""; + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/changebracket.java b/Basic_Of_Algorithm/src/Today_22_05_12/changebracket.java new file mode 100644 index 0000000..ba24c08 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/changebracket.java @@ -0,0 +1,68 @@ +package Today_22_05_12; + +public class changebracket { + + + public static void main(String[] args) { + + String p = ")("; + + if(p.isEmpty())System.out.println("nope"); + else { + + String answer = change(p); + System.out.println(answer); + } + + + + } + + static String change(String w) { + + if(w.isEmpty()) return ""; + + String u = ""; + String v = ""; + + int l = 0; + int r = 0; + int i; + + for(i=0;i() { + + @Override + public int compare(int[] o1, int[] o2) { + + if(o1[1]==o2[1]) { + return o1[0] - o2[0]; + } + return o1[1]-o2[1]; + } + + }); + + for(int i=0;i=end_time) { + end_time = rooms[i][1]; + count++; + } + + + } + + System.out.println("답 : " + count); + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/gameMap.java b/Basic_Of_Algorithm/src/Today_22_05_12/gameMap.java new file mode 100644 index 0000000..97469a7 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/gameMap.java @@ -0,0 +1,52 @@ +package Today_22_05_12; + +import java.util.*; + +public class gameMap { + + public static void main(String[] args) { + + int[][]maps = {{1,0,1,1,1},{1,0,1,0,1},{1,0,1,1,1},{1,1,1,0,1},{0,0,0,0,1}}; + + int answer = 0; + + Queue q = new LinkedList<>(); + + + int[][]temp = new int[maps.length][maps[0].length]; + + int [][] move = {{0,1},{1,0},{0,-1},{-1,0}}; + + + temp[0][0] = 1; + + q.add(new int[] {0,0}); + + while(!q.isEmpty()) { + + int[]cur = q.poll(); + + int i = cur[0]; + int j = cur[1]; + + for(int d=0;d<4;d++) { + + int ni = i + move[d][0]; + int nj = j + move[d][1]; + + if(ni<0||nj<0||maps.length-1 q = new LinkedList<>(); + + int[] position = new int[100001]; + + + position[sb] = 0; + + q.add(sb); + + while(!q.isEmpty()) { + + + int p = q.poll(); + + if(position[bro]!=0) break; + + if(position[p-1] ==0 && p-1>=0) { + position[p-1] = position[p] + 1; + q.add(p-1); + } + + if(position[p+1] ==0 && p+1<=position.length) { + position[p+1] = position[p] + 1; + q.add(p+1); + + } + if(position[p*2] ==0 && p*2<=position.length) { + position[p*2] = position[p] + 1; + q.add(p*2); + + } + + + } + + if(sb==bro) position[bro] = 0; + System.out.println(position[bro] + " 초"); + + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/hideAndFind.java b/Basic_Of_Algorithm/src/Today_22_05_12/hideAndFind.java new file mode 100644 index 0000000..a8bbb4e --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/hideAndFind.java @@ -0,0 +1,66 @@ +package Today_22_05_12; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.PriorityQueue; + +public class hideAndFind { + + public static void main(String[] args) { + + int[][]jobs = {{0, 3}, {1, 9}, {2, 6}}; + + int answer = 0; + + Arrays.sort(jobs, new Comparator() { + + @Override + public int compare(int[] o1, int[] o2) { + if(o1[0]==o2[0]) { + return o1[1] - o2[1]; + } + return o1[0] - o2[0]; + } + + }); + + + for(int i=0;i q = new PriorityQueue(new Comparator() { + + @Override + public int compare(int[] o1, int[] o2) { + // TODO Auto-generated method stub + return o1[1]-o2[1]; + } + + }); + + q.offer(jobs[0]); + int end = jobs[0][0]; + int sum = 0; + int idx = 1; + + while(!q.isEmpty()) { + int [] cur = q.poll(); + end += cur[1]; + sum += end - cur[0]; + System.out.println(sum); + + while(idx < jobs.length && jobs[idx][0] <= end) { + q.offer(jobs[idx++]); + } + + if(idx < jobs.length && q.isEmpty()) { + end = jobs[idx][0]; + q.offer(jobs[idx++]); + } + } + + + System.out.println(sum/jobs.length); + } +} \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/rightbiggersoo.java b/Basic_Of_Algorithm/src/Today_22_05_12/rightbiggersoo.java new file mode 100644 index 0000000..924108d --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/rightbiggersoo.java @@ -0,0 +1,37 @@ +package Today_22_05_12; + +import java.util.*; + +public class rightbiggersoo { + + public static void main(String[] args) { + + int []A = {3,5,2,7}; + int[]answer = new int[A.length]; + + Stack ans = new Stack<>(); + Stack tmp = new Stack<>(); + + for(int i = A.length-1; i > -1 ; i--) { + + int num = A[i]; + + while(!tmp.isEmpty() && (num >= tmp.peek())) { + tmp.pop(); + } + + if(tmp.isEmpty()) { + ans.add(-1); + }else { + ans.add(tmp.peek()); + } + + tmp.add(num); + + } + + for(int i = 0 ; i < answer.length;i++) System.out.println(ans.pop()); + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_12/rooms.java b/Basic_Of_Algorithm/src/Today_22_05_12/rooms.java new file mode 100644 index 0000000..3801026 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_12/rooms.java @@ -0,0 +1,46 @@ +package Today_22_05_12; + +import java.util.*; + +public class rooms { + + static int answer = Integer.MAX_VALUE; + + public static void main(String[] args) { + + int[][] rooms = {{1,4},{3,5},{0,6},{5,7},{3,8}, + {5,9},{6,10},{8,11},{8,12},{2,13}, + {12,14}}; + + + + Arrays.sort(rooms, new Comparator() { + public int compare(int[]o1,int[]o2) { + + if(o1[1]==o2[1]) { + + return o1[0] - o2[0]; + } + return o1[1]-o2[1]; + + } + }); + + for(int i=0;i=end_time) { + end_time = rooms[i][1]; + count++; + } + } + + System.out.println(count); + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_13/dictionary.java b/Basic_Of_Algorithm/src/Today_22_05_13/dictionary.java new file mode 100644 index 0000000..5d3c17a --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_13/dictionary.java @@ -0,0 +1,53 @@ +package Today_22_05_13; + +import java.util.ArrayList; + +public class dictionary { + + public static void main(String[] args) { + + String msg = "KAKAO"; + + ArrayList dic = new ArrayList<>(); + ArrayList ans = new ArrayList<>(); + + String alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + dic.add("&&"); + + for(int i=0;i q = new LinkedList<>(); + + int[]check = new int[100001]; + + check[finder] = 0; + + q.add(finder); + + while(!q.isEmpty()) { + + int pos = q.poll(); + + if(check[hider]!=0 || pos>100000) break; + + if(pos-1 >= 0 && check[pos-1] ==0 ) { + check[pos-1] = check[pos] + 1; + q.add(pos-1); + } + if(pos+1 < check.length && check[pos-1] ==0 ) { + check[pos+1] = check[pos] + 1; + q.add(pos+1); + } + if(pos*2 >= 0 && check[pos*2] ==0 ) { + check[pos*2] = check[pos] + 1; + q.add(pos*2); + } + + } + + + System.out.println(check[hider]); + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_13/practice.java b/Basic_Of_Algorithm/src/Today_22_05_13/practice.java new file mode 100644 index 0000000..e2bcd16 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_13/practice.java @@ -0,0 +1,47 @@ +package Today_22_05_13; + +import java.util.Comparator; +import java.util.Arrays; + +public class practice { + + public static void main(String[] args) { + + int[][] rooms = {{1,4},{3,5},{0,6},{5,7},{3,8}, + {5,9},{6,10},{8,11},{8,12},{2,13}, + {12,14}}; + + + Arrays.sort(rooms,new Comparator() { + + @Override + public int compare(int[] o1, int[] o2) { + // TODO Auto-generated method stub + if(o1[1]==o2[1]) { + return o1[0]-o2[0]; + } + return o1[1]-o2[1]; + } + + }); + + + + int end_time = 0; + int count = 0; + + + for(int i=0;i=end_time) { + end_time = rooms[i][1]; + count++; + } + + } + + + System.out.println(count); + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_13/right.java b/Basic_Of_Algorithm/src/Today_22_05_13/right.java new file mode 100644 index 0000000..b826d66 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_13/right.java @@ -0,0 +1,41 @@ +package Today_22_05_13; + +import java.util.Stack; + +public class right { + + public static void main(String[] args) { + + int [] arr = {3,5,1,7}; + + Stack temp = new Stack<>(); + Stack ans = new Stack<>(); + + + + for(int i=arr.length-1;i>-1;i--) { + + int num = arr[i]; + + while(!temp.isEmpty() && num>=temp.peek()) { + temp.pop(); + } + + if(temp.isEmpty()) { + ans.add(-1); + }else { + ans.add(temp.peek()); + } + temp.add(num); + + } + + int []result = new int[arr.length]; + + for(int i=0;i opArr = new ArrayList<>(); + static ArrayList numArr = new ArrayList<>(); + + + public static void main(String[] args) { + + String expression = "100-200*300-500+20"; + + input(expression); + + dfs(new char[3],0); + + System.out.println(answer); + + + + } + + static Long change(char ch,long a, long b) { + if(ch=='+') return a+b; + else if(ch=='-') return a-b; + else if(ch=='*') return a*b; + else return (long) 0; + + } + + + static void dfs(char[]p,int count) { + + if(count==3) { + + ArrayListnumList =new ArrayList<>(numArr); + ArrayListopList =new ArrayList<>(opArr); + + for(int i=0;i='0'&& ch<='9') num += ch; + else { + numArr.add(Long.parseLong(num)); + opArr.add(ch); + num=""; + } + + + + } + + numArr.add(Long.parseLong(num)); + + + } + + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_13/testCode.java b/Basic_Of_Algorithm/src/Today_22_05_13/testCode.java new file mode 100644 index 0000000..698046c --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_13/testCode.java @@ -0,0 +1,25 @@ +package Today_22_05_13; + +import java.util.Stack; + +public class testCode { + + public static void main(String[] args) { + + int n = 43674; + int k = 3; + int answer = 0; + + String num = ""; + + while(n>0) { + + num = n%k + num; + n /= k; + + } + + System.out.println(num); + + } +}