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); + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_15/bfs.java b/Basic_Of_Algorithm/src/Today_22_05_15/bfs.java new file mode 100644 index 0000000..949ae98 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_15/bfs.java @@ -0,0 +1,57 @@ +package Today_22_05_15; + +import java.util.LinkedList; +import java.util.Queue; + +public class bfs { + + public static void main(String[] args) { + + int sb = 5; + int bro = 17; + + + + Queue 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_16/test.java b/Basic_Of_Algorithm/src/Today_22_05_16/test.java new file mode 100644 index 0000000..f01b73d --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_16/test.java @@ -0,0 +1,51 @@ +package Today_22_05_16; + +import java.util.LinkedList; +import java.util.Queue; + +public class test { + + public static void main(String[] args) { + + int a = 5; + int b = 17; + + int[]visited = new int[10001]; + + + Queue q = new LinkedList<>(); + + visited[a] = 0; + + q.add(a); + + while(!q.isEmpty()) { + + int now = q.poll(); + + if(visited[b]!=0 || now >=10000) break; + + if(now-1>=0 && visited[now-1] ==0) { + visited[now-1] = visited[now] + 1; + q.add(now-1); + } + + if(now+1<=10000 && visited[now+1] ==0) { + visited[now+1] = visited[now] + 1; + q.add(now+1); + } + + if(now*2<=10000 && visited[now*2] ==0) { + visited[now*2] = visited[now] + 1; + q.add(now*2); + } + + } + + + + System.out.println(visited[b]); + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_16/test2.java b/Basic_Of_Algorithm/src/Today_22_05_16/test2.java new file mode 100644 index 0000000..6b7cce6 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_16/test2.java @@ -0,0 +1,56 @@ +package Today_22_05_16; + +import java.util.Queue; +import java.util.LinkedList; + +public class test2 { + + public static void main(String[] args) { + + + int [][] map = {{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}}; + + + Queue q = new LinkedList<>(); + + int [][] temp = new int[map.length][map[0].length]; + + temp[0][0] = 1; + + q.add(new int[] {0,0}); + + int [][] move = {{0,1},{1,0},{0,-1},{-1,0}}; + + while(!q.isEmpty()) { + + int []c = q.poll(); + + int ci = c[0]; + int cj = c[1]; + + for(int d=0;d<4;d++) { + + int ni = ci + move[d][0]; + int nj = cj + move[d][1]; + + if(ni<0||nj<0||map.length-1 map = new HashMap<>(); + static ArrayList answerList = new ArrayList<>(); + + public static void main(String[] args) { + + String [] orders = {"ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"}; + int [] course = {2,3,4}; + + for(int i=0;i maxValue = new ArrayList<>(map.values()); + int max = Collections.max(maxValue); + if(max>1) { + for(String key : map.keySet()) { + if(map.get(key)==max) { + answerList.add(key); + } + } + } + } + + + map.clear(); + } + + Collections.sort(answerList); + + String[]answer = new String[answerList.size()]; + + for(int i=0;i> 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 [] answer = new int[query.length]; + + for(String str : info) { + String []temp = str.split(" "); + dfs(temp,"",0); + } + + for(String key:map.keySet()) { + Collections.sort(map.get(key)); + } + + for(int i =0;i list = map.get(now); + + int score = Integer.parseInt(infoScore); + + int start = 0, end = list.size()-1; + + while(start<=end) { + + int mid = (start+end)/2; + + if(list.get(mid)()); + } + map.get(now).add(Integer.parseInt(temp[4])); + return; + } + + dfs(temp,now+"-",count+1); + dfs(temp,now+temp[count],count+1); + + + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_19/soosick.java b/Basic_Of_Algorithm/src/Today_22_05_19/soosick.java new file mode 100644 index 0000000..db211b1 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_19/soosick.java @@ -0,0 +1,85 @@ +package Today_22_05_19; + +import java.util.*; + +public class soosick { + + static long answer = 0; + static ArrayList numList = new ArrayList<>(); + static ArrayList opList = new ArrayList<>(); + static char [] op = {'+','-','*'}; + static boolean []visited = new boolean[3]; + + public static void main(String[] args) { + + String expression = "100-200*300-500+20"; + + String num = ""; + for(int i=0;i='0' && ch <= '9') { + num += ch; + }else { + numList.add(Long.parseLong(num)); + num=""; + opList.add(ch); + } + } + + numList.add(Long.parseLong(num)); + + 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) { + ArrayList numArr = new ArrayList<>(numList); + ArrayList opArr = new ArrayList<>(opList); + + for(int i=0;i q = new LinkedList<>(); + + int[][]temp = new int[maps.length][maps[0].length]; + + temp[0][0] = 1; + + q.add(new int[] {0,0}); + + int[][]move = {{0,1},{1,0},{0,-1},{-1,0}}; + + while(!q.isEmpty()) { + + int [] cur = q.poll(); + + int ni = cur[0]; + int nj = cur[1]; + + for(int d=0;d<4;d++) { + + int newI = ni + move[d][0]; + int newJ = nj + move[d][1]; + + if(newI<0||newJ<0||maps.length-1=arr[i]) { + + answer += cash/arr[i]; + cash = cash%arr[i]; + } + if(cash==0)break; + } + + + System.out.println(answer); + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_20/greedy_atm.java b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_atm.java new file mode 100644 index 0000000..50be8e6 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_atm.java @@ -0,0 +1,33 @@ +package Today_22_05_20; + +import java.util.Scanner; +import java.util.Arrays; + +public class greedy_atm { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int answer = 0; + + int n = scan.nextInt(); + + int[]man = new int[n]; + + for(int i=0;i=coin) { + System.out.println(coin); + answer++; + k -= coin; + } + + + } + + System.out.println(answer); + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_20/greedy_coin2.java b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_coin2.java new file mode 100644 index 0000000..11d3b15 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_coin2.java @@ -0,0 +1,35 @@ +package Today_22_05_20; + +import java.util.Scanner; +import java.util.Arrays; +import java.util.Collections; +public class greedy_coin2 { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + + int n = scan.nextInt(); + int k = scan.nextInt(); + + int answer = 0; + + Integer[]arr = new Integer[n]; + + + for(int i=0;i-1;i--) { + + if(arr[i]<=k) { + answer += k/arr[i]; + k = k%arr[i]; + } + + } + + System.out.println(answer); + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_20/greedy_sugar.java b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_sugar.java new file mode 100644 index 0000000..8afced0 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_sugar.java @@ -0,0 +1,40 @@ +package Today_22_05_20; + +import java.io.InputStreamReader; +import java.io.BufferedReader; +public class greedy_sugar { + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + int n = Integer.parseInt(br.readLine()); + + //3 //5 + int answer = 0; + + //5의 배수도 3의 배수도 아닌 경우에도 나눠 떨어지는 애들이 있음! + + + while(true) { + + if(n%5==0) { + answer += n/5; + break; + }else { + answer ++; + n -= 3; + } + + if(n<0) { + answer = -1; + break; + } + + } + + System.out.println(answer); + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_20/greedy_wordsMath.java b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_wordsMath.java new file mode 100644 index 0000000..1cd2aa4 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_20/greedy_wordsMath.java @@ -0,0 +1,42 @@ +package Today_22_05_20; + +import java.util.Scanner; + +public class greedy_wordsMath { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int n = scan.nextInt(); + + int[]arr = new int[n]; + + for(int i=0;i-1;i--) { + + int pre = arr[i]; + while(nPoint<=pre) { + + answer++; + pre--; + + } + + nPoint = pre; + + + } + + + System.out.println(answer); + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_20/room.java b/Basic_Of_Algorithm/src/Today_22_05_20/room.java new file mode 100644 index 0000000..279c1db --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_20/room.java @@ -0,0 +1,48 @@ +package Today_22_05_20; + +import java.util.Scanner; +import java.util.Arrays; +import java.util.Comparator; + +public class room { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int n = scan.nextInt(); + + int[][]arr = new int[n][2]; + + int answer = 0 ; + + for(int i=0;i() { + + @Override + public int compare(int[] o1, int[] o2) { + if(o1[1]==o2[1]) return o1[0] - o2[0]; + else return o1[1] - o2[1]; + } + }); + + int end_time = 0; + + for(int i=0;i map = new HashMap<>(); + + String [] splitString = s.split(","); + + for(int i=0;i keySet = new ArrayList<>(map.keySet()); + Collections.sort(keySet, (o1,o2)-> map.get(o2).compareTo(map.get(o1))); + + System.out.println(keySet); + + } +} 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=num) { + end = mid; + }else { + start = mid+1; + } + + } + + return start; + } + static int upperBound(int num,int []arr) { + + + int start = 0; + int end = arr.length; + + + while(startnum) { + end = mid; + }else { + start = mid+1; + } + + } + + return start; + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_26/programmers_bruteForce.java b/Basic_Of_Algorithm/src/Today_22_05_26/programmers_bruteForce.java new file mode 100644 index 0000000..c44f1e1 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_26/programmers_bruteForce.java @@ -0,0 +1,70 @@ +package Today_22_05_26; + +import java.util.*; + +public class programmers_bruteForce { + + static int answer = 0; + static Setset = new HashSet<>(); + + + public static void main(String[] args) { + + + String numbers = "17"; + + + + boolean[]visited = new boolean[numbers.length()]; + + dfs(numbers,visited,""); + + System.out.println(set.size()); + System.out.println(set); + + } + + static void dfs(String numbers,boolean [] visited,String now) { + + if(!now.isEmpty()) { + + + int temp = Integer.parseInt(now); + boolean flag = true; + + if(temp==2) flag = true; + else if(temp==1 || temp==0) flag = false; + + + for(int i=2;i<=Math.sqrt(temp);i++) { + + if(temp%i==0) { + flag = false; + break; + } + + } + + if(flag) set.add(temp); + } + + + + + for(int i = 0 ; i temp = new Stack<>(); + Stack pra = new Stack<>(); + + //5 3 2 2 0 + + for(int i=arr.length-1;i>-1;i--) { + + int num = arr[i]; + + while(!temp.isEmpty() && num>= temp.peek()) { + temp.pop(); + } + + if(temp.isEmpty()) { + pra.add(-1); + }else { + pra.add(temp.peek()); + } + + temp.add(num); + + + + + } + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_26/test.java b/Basic_Of_Algorithm/src/Today_22_05_26/test.java new file mode 100644 index 0000000..941152c --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_26/test.java @@ -0,0 +1,35 @@ +package Today_22_05_26; + +import java.util.*; + +public class test { + + public static void main(String[] args) { + + + int[]arr = {3,7,1,5}; + //-1 5 -1 7 stack + + Stacktemp = new Stack<>(); + Stackans = 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); + + } + + + System.out.println(ans); + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_26/twoPointer.java b/Basic_Of_Algorithm/src/Today_22_05_26/twoPointer.java new file mode 100644 index 0000000..4e8fd61 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_26/twoPointer.java @@ -0,0 +1,48 @@ +package Today_22_05_26; + +import java.util.*; + +public class twoPointer { + + public static void main(String[] args) { + + int [] two = {1,1,2,2,3,3}; + //1,1,2,2,3,5,7 + int target = 4; + int answer = 0; + //답 = 2 + int start = 0; + int end = two.length-1; + Arrays.sort(two); + + + + while(start<=end) { + + + int sum = two[start] + two[end]; + + if(sumanswerList = new ArrayList<>(); + + public static void main(String[] args) { + + int[] info = {2,1,1,1,0,0,0,0,0,0,0}; + int n = 5; + apeach = info.clone(); + ryan = new int[apeach.length]; + visited = new boolean[apeach.length]; + count = n; + + answer = solution(n,info); + + for(int i=0;iapeach[i]) r += 10 - i; + else a += 10 - i; + } + + + if(r>a) { + int diff = r-a; + if(max{ + for(int i=10;i>-1;i--) { + if(o1[i]!=o2[i]) return o2[i] - o1[i]; + } + return 0; + }); + + + if(answerList.isEmpty()) return new int[] {-1}; + + answer = new int[info.length]; + + for(int i=0;i1) answer[i] = 1; + + } + + for(int i : answer)System.out.println(i); + + + } + + static int binary(int num,int[] arr) { + + + int start = 0; + int end = arr.length-1; + int count = 0; + + while(start<=end) { + + int mid = (start+end) / 2; + + if(num>=arr[mid]) start = mid+1; + else if(start==end)break; + else if(num=arr[mid]) start = mid+1; + else end = mid-1; + + } + + return start; + + } + + static int lowerSearch(int num, int []arr) { + + int start = 0; + int end = arr.length-1; + + while(start<=end) { + + + + int mid = (start+end)/2; + + + + if(num>arr[mid]) start = mid+1; + else end = mid-1; + + + + + } + + return start; + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo3.java b/Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo3.java new file mode 100644 index 0000000..fee42cc --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_27/binarySearchNo3.java @@ -0,0 +1,61 @@ +package Today_22_05_27; + +import java.util.Scanner; +import java.util.Arrays; + +public class binarySearchNo3 { + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int k = scan.nextInt(); + int n = scan.nextInt(); + + int[]arr = new int[k]; + + for(int i =0;i 0) { + temp += (arr[i]-mid); + } + } + + + if(tempstack = new Stack<>(); + + for(int j=0;jq = new LinkedList<>(); + + + q.add(new int[] {n,m,0}); + + + while(!q.isEmpty()) { + + int[]cur = q.poll(); + + int cn = cur[0]; + int cm = cur[1]; + + + if(cn==cm) break; + + if(cn>100000) break; + + + if(cm+1<10000 && check[cm+1]==0) { + check[cm+1] = check[cm] +1; + q.add(new int[] {cn,cm+1}); + } + + if(cm-1>0 && check[cm-1]==0) { + check[cm-1] = check[cm] +1; + q.add(new int[] {cn,cm-1}); + } + + if(cm*2<10000 && check[cm*2]==0) { + check[cm*2] = check[cm] +1; + q.add(new int[] {cn,cm*2}); + } + + } + + + System.out.println(check[n]); + + + + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_27/disk.java b/Basic_Of_Algorithm/src/Today_22_05_27/disk.java new file mode 100644 index 0000000..3c1a0e1 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_27/disk.java @@ -0,0 +1,67 @@ +package Today_22_05_27; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.PriorityQueue; + +public class disk { + + public static void main(String[] args) { + + int[][]jobs = {{0, 3}, {1, 9}, {2, 6}}; + int answer = 0; + + Arrays.sort(jobs,(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) { + + 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(end + " end"); + System.out.println(sum); + + while(idx < jobs.length && jobs[idx][0] <= end) { + q.offer(jobs[idx++]); + } + + + + if(idx q = new PriorityQueue<>(); + + + for(int i : scoville) q.offer(i); + + + while(k>q.peek()) { + + if(q.size()<2)break; + + + int first = q.poll(); + int second = q.poll(); + + int newOne = first + (second*2); + + q.offer(newOne); + answer++; + + + } + + + System.out.println(answer); + + + + } + + + + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_27/quate.java b/Basic_Of_Algorithm/src/Today_22_05_27/quate.java new file mode 100644 index 0000000..1b48737 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_27/quate.java @@ -0,0 +1,55 @@ +package Today_22_05_27; + +public class quate { + + static int [] answer = new int[2]; + + public static void main(String[] args) { + + + int [][] arr = {{1,1,1,1,1,1,1,1},{0,1,1,1,1,1,1,1},{0,0,0,0,1,1,1,1},{0,1,0,0,1,1,1,1},{0,0,0,0,0,0,1,1},{0,0,0,0,0,0,0,1},{0,0,0,0,1,0,0,1},{0,0,0,0,1,1,1,1}}; + + + + dfs(arr,arr.length,0,0); + + + System.out.println(answer[0]+" : "+answer[1]); + + } + + static boolean check(int[][]arr,int size,int x, int y) { + + for(int i=x;i tmp = new Stack<>(); + Stack ans = new Stack<>(); + + for(int i=arr.length-1;i>-1;i--) { + + int num = arr[i]; + + + while(!tmp.isEmpty() && num>=tmp.peek()) { + tmp.pop(); + } + + if(tmp.isEmpty()) { + ans.add(-1); + }else { + ans.add(tmp.peek()); + } + + tmp.add(num); + + + + + } + System.out.println(ans); + + for(int i=0;i 0) sum += i-mid; + + if(sum answerList = new ArrayList<>(); + static int maxValue = Integer.MIN_VALUE; + + public static void main(String[] args) { + + + int n = 10; + int[]info = {0,0,0,0,0,0,0,0,3,4,3}; + + apeach = info.clone(); + ryan = new int[apeach.length]; + + + arrow = n; + + dfs(0,0); + + + if(answerList.isEmpty()) answerList.add(new int[] {-1}); + else { + + Collections.sort(answerList,(o1,o2)-> { + + for(int i=o1.length-1;i>-1;i--) { + if(o1[i]!=o2[i]) return o2[i] - o1[i]; + } + + return 0; + + }); + + + } + + for(int i : answerList.get(0)) System.out.print(i+","); + + } + + static void dfs(int start,int goal) { + + if(goal==arrow) { + int r = 0; + int a = 0; + + for(int i=0;i=ryan[i]) a += 10 - i; + else r += 10-i; + + } + + if(r>a) { + int diff = r-a; + if(maxValue dic = new ArrayList<>(); + ArrayListans = new ArrayList<>(); + + dic.add("^&#("); + + for(int i=0;ist = new Stack<>(); + + for(int i=0;iq = new LinkedList<>(); + + int [][]temp = new int[maps.length][maps[0].length]; + + temp[0][0] = 1; + + 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-12"}; + dt = data; + dfs(0,""); + + System.out.println(answer); + + } + static boolean check(String now) { + + for(String str : dt) { + + int pos1 = now.indexOf(str.charAt(0)); + int pos2 = now.indexOf(str.charAt(2)); + int op = str.charAt(3); + int idx = str.charAt(4) - '0'; + + if(op=='=') { + if(!(Math.abs(pos1-pos2)==idx+1)) return false; + }else if(op=='>') { + if(!(Math.abs(pos1-pos2)>idx+1)) return false; + }else if(op=='<') { + if(!(Math.abs(pos1-pos2) " + to); + return; + } + + hanoi(n-1,start,to,mid); + + System.out.println(start+" -> " +to); + + hanoi(n-1,mid,start,to); + } +} \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/lastWordLinked.java b/Basic_Of_Algorithm/src/Today_22_05_31/lastWordLinked.java new file mode 100644 index 0000000..dd2b1cc --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/lastWordLinked.java @@ -0,0 +1,52 @@ +package Today_22_05_31; + +import java.util.ArrayList; + +public class lastWordLinked { + + public static void main(String[] args) { + + int n = 3; + + String [] words = {"tank", "kick", "know", "wheel", "land", "dream", "mother", "robot", "tank"}; + + int []answer = new int[2]; + + char last = words[0].charAt(words[0].length()-1); + + int person = 2; + int round = 1; + + ArrayListwordsList = new ArrayList<>(); + + wordsList.add(words[0]); + + for(int i=1;in) { + round++; + person = 1; + } + + } + + System.out.println(answer[0]+" : "+answer[1]); + + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/menuRenewal.java b/Basic_Of_Algorithm/src/Today_22_05_31/menuRenewal.java new file mode 100644 index 0000000..4981387 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/menuRenewal.java @@ -0,0 +1,66 @@ +package Today_22_05_31; + +import java.util.HashMap; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +public class menuRenewal { + + static HashMap map = new HashMap<>(); + static ArrayListanswerList = new ArrayList<>(); + + public static void main(String[] args) { + + String[]orders = {"ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"}; + int[]course = {2,3,4}; + + for(int i=0;imaxList = new ArrayList<>(map.values()); + int max = Collections.max(maxList); + if(max>1) { + for(String key : map.keySet()) { + if(max==map.get(key)) { + answerList.add(key); + } + } + } + } + + map.clear(); + } + + Collections.sort(answerList); + + System.out.println(answerList); + + } + static void dfs(int count,String order,String now) { + + if(count==0) { + map.put(now, map.getOrDefault(now, 0)+1); + return; + } + + for(int i=0;i map = new HashMap<>(); + static TreeMap tree = new TreeMap<>(); + + public static void main(String[] args) { + + int[]fees = {180,5000,10,600}; + String []records = {"05:34 5961 IN", "06:00 0000 IN", "06:34 0000 OUT", "07:59 5961 OUT", "07:59 0148 IN", "18:59 0000 IN", "19:09 0148 OUT", "22:59 5961 IN", "23:00 5961 OUT"}; + + + for(String str : records) { + + String [] temp = str.split(" "); + + int time = change(temp[0]); + String num = temp[1]; + String action = temp[2]; + + if(action.equals("IN")) map.put(num, time); + else { + + if(!tree.containsKey(num)) tree.put(num, 0); + + tree.put(num, tree.get(num) + (time - map.get(num))); + map.remove(num); + + } + } + + if(!map.isEmpty()) { + for(String key : map.keySet()) { + if(!tree.containsKey(key)) tree.put(key, 0); + + tree.put(key, tree.get(key) + ((23 * 60) + 59 - map.get(key))); + + } + } + + System.out.println(tree); + + ArrayList answerList = new ArrayList<>(); + + + + for(String key : tree.keySet()) { + + int time = tree.get(key); + + if(time<=fees[0]) { + answerList.add(fees[1]); + continue; + } + time -= fees[0]; + double result = fees[1]; + double check = (double)time/fees[2]; + + check = Math.ceil(check); + + result += fees[3] * check; + answerList.add((int)result); + + + } + + System.out.println(answerList); + + + } + static int change(String time) { + + String [] temp = time.split(":"); + + int hour = Integer.parseInt(temp[0]) * 60; + int min = Integer.parseInt(temp[1]) + hour; + + return min; + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/quad.java b/Basic_Of_Algorithm/src/Today_22_05_31/quad.java new file mode 100644 index 0000000..2a70cb0 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/quad.java @@ -0,0 +1,71 @@ +package Today_22_05_31; + +public class quad { + + + public static void main(String[] args) { + + solution solution = new solution(); + + int[][]arr1 = {{1,1,0,0},{1,0,0,0},{1,0,0,1},{1,1,1,1}}; + int[][]arr2 = {{1,1,1,1,1,1,1,1},{0,1,1,1,1,1,1,1},{0,0,0,0,1,1,1,1},{0,1,0,0,1,1,1,1},{0,0,0,0,0,0,1,1},{0,0,0,0,0,0,0,1},{0,0,0,0,1,0,0,1},{0,0,0,0,1,1,1,1}}; + int[]result1 = solution.solution(arr1); + int[]result2 = solution.solution(arr2); + + System.out.print(result1[0]+" , "); + System.out.println(result1[1]); + System.out.print(result2[0]+" , "); + System.out.println(result2[1]); + + } +} + +class solution{ + + + int[]answer; + + public int[]solution(int[][]arr) { + + answer= new int[2]; + + + + change(arr,0,0,arr.length); + + + + + + + return answer; + } + + boolean check(int[][]arr,int x,int y,int size) { + + for(int i=x;iopList = new ArrayList<>(); + static ArrayListnumList = new ArrayList<>(); + static long answer = 0; + + public static void main(String[] args) { + + + String expression = "100-200*300-500+20"; + + check(expression); + + boolean[]visited = new boolean[3]; + + dfs(new char[3],0,visited); + + System.out.println(answer); + + } + static long change(long a,long b,char ch) { + if(ch=='+')return a+b; + else if(ch=='-')return a-b; + else if(ch=='*')return a*b; + return 0; + } + static void dfs(char[]p,int num,boolean[]visited) { + + if(num==3) { + + ArrayList numArr = new ArrayList<>(numList); + ArrayList opArr = new ArrayList<>(opList); + + for(int i=0;i='0' && ch<='9') num += ch; + else { + numList.add(Long.parseLong(num)); + num=""; + opList.add(ch); + } + + } + + numList.add(Long.parseLong(num)); + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/targetNumber.java b/Basic_Of_Algorithm/src/Today_22_05_31/targetNumber.java new file mode 100644 index 0000000..1d0edf6 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/targetNumber.java @@ -0,0 +1,36 @@ +package Today_22_05_31; + +public class targetNumber { + + static int answer= 0; + static int tar; + public static void main(String[] args) { + + int[]numbers = {1,1,1,1,1}; + int target = 3; + tar = target; + dfs(numbers,0,0); + + System.out.println(answer); + + } + + static void dfs(int[]numbers,int now,int count) { + + if(count==numbers.length) { + + if(tar==now) answer++; + + + return; + } + + + dfs(numbers,now + numbers[count],count+1); + dfs(numbers,now - numbers[count],count+1); + + + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/treeCut.java b/Basic_Of_Algorithm/src/Today_22_05_31/treeCut.java new file mode 100644 index 0000000..d112dfc --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/treeCut.java @@ -0,0 +1,37 @@ +package Today_22_05_31; + +import java.util.Collections; + +public class treeCut { + + public static void main(String[] args) { + + int[]arr = {20,15,10,17}; + int cut = 7; + + int min = 0; + int max = 0; + + for(int i : arr) if(max0) count += i-mid; + + if(count>cut) min = mid+1; + else max = mid; + + + + } + + System.out.println(min); + + + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_05_31/tuple.java b/Basic_Of_Algorithm/src/Today_22_05_31/tuple.java new file mode 100644 index 0000000..ae995ca --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_05_31/tuple.java @@ -0,0 +1,51 @@ +package Today_22_05_31; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; + +public class tuple { + + public static void main(String[] args) { + + String s = "{{4,2,3},{3},{2,3,4,1},{2,3}}"; + + s = s.replaceAll("\\{", ""); + s = s.replaceAll("\\}", ""); + + + HashMap map = new HashMap<>(); + + String []temp = s.split(","); + + for(String str : temp) { + int num = Integer.parseInt(str); + map.put(num,map.getOrDefault(num, 0)+1); + } + + + ArrayList answerList = new ArrayList<>(map.keySet()); + + + Collections.sort(answerList, new Comparator() { + + @Override + public int compare(Integer o1, Integer o2) { + if(map.get(o1)==map.get(o2)) return map.get(o1)- map.get(o2); + else return map.get(o2)- map.get(o1); + } + + }); + + + + int[]answer= new int[answerList.size()]; + + for(int i=0;i answerList = new ArrayList<>(); + + public static void main(String[] args) { + + int[]info = {0,0,1,2,0,1,1,1,1,1,1}; + int n = 9; + + apeach = info.clone(); + count = n; + ryan = new int[info.length]; + + dfs(0,0); + + int [] answer; + + if(answerList.isEmpty()) answer = new int[] {-1}; + + else { + + Collections.sort(answerList,(o1,o2)->{ + + for(int i=10;i>-1;i--) { + if(o1[i]!=o2[i]) return o2[i] - o1[i]; + } + + return 0; + + }); + + answer = new int[apeach.length]; + + for(int i=0;iapeach[i]) r += 10 - i; + else a += 10 - i; + } + + if(r>a) { + int diff = r - a; + if(diff>maxvalue) { + maxvalue = diff; + answerList.clear(); + answerList.add(ryan.clone()); + + }else if(diff==maxvalue) { + answerList.add(ryan.clone()); + } + } + + return; + } + + + for(int i=0;i<11;i++) { + ryan[i]++; + dfs(i,arrow+1); + ryan[i]--; + } + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_06_02/coronaTest.java b/Basic_Of_Algorithm/src/Today_22_06_02/coronaTest.java new file mode 100644 index 0000000..77a4024 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_02/coronaTest.java @@ -0,0 +1,90 @@ +package Today_22_06_02; + +public class coronaTest { + + public static void main(String[] args) { + + String[][]places = {{"POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"}, {"POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"}, {"PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"}, {"OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"}, {"PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"}}; + int []result = new int[places.length]; + + for(int i=0;i w) { + map[a][b] = w; + map[b][a] = w; + } + + } + + int [] dist = new int[n+1]; + for(int i = 2; i <= n ; i++) { + dist[i] = INF; + } + + boolean[] visited = new boolean[n+1]; + visited[1] = true; + + + for(int i=1; i <=n-1 ; i++) { + + int min_idx = 1; + int min_value = INF; + for(int j=2;j<=n;j++) { + if(!visited[j] && dist[j]dist[min_idx] + map[min_idx][j]) { + dist[j] = dist[min_idx] + map[min_idx][j]; + } + } + + } + + for(int i=1;i<=n;i++) { + if(dist[i]<=k) answer++; + } + + for(int i : dist)System.out.print(i+","); + System.out.println(); + System.out.println(answer); + } + +} \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/Today_22_06_02/hanoi.java b/Basic_Of_Algorithm/src/Today_22_06_02/hanoi.java new file mode 100644 index 0000000..408945d --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_02/hanoi.java @@ -0,0 +1,34 @@ +package Today_22_06_02; + +public class hanoi { + + public static void main(String[] args) { + + int n = 4; + + int [] arr = {1,2,3}; + + hanoi(arr[0],arr[1],arr[2],n); + + + //n개를 옮기는 문제는 n-1로 세분화되고 다시 n-1를 위해 1를 옮기는걸 세분화 시킨다 + // a -> b (n-1)개 옮기기 + // b - > c (n-1)개 옮기기 + //n ==1 마지막에 남은거 옮기기 + + } + + static void hanoi(int from, int by, int to,int n) { + + if(n==1) { + System.out.println(from + " - > " + to); + return; + } + + hanoi(from, to, by, n-1); + System.out.println(from + " - > " + to); + hanoi(by,from,to,n-1); + + } + +} diff --git a/Basic_Of_Algorithm/src/Today_22_06_02/openChatting.java b/Basic_Of_Algorithm/src/Today_22_06_02/openChatting.java new file mode 100644 index 0000000..f46536f --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_02/openChatting.java @@ -0,0 +1,57 @@ +package Today_22_06_02; + +import java.util.ArrayList; +import java.util.HashMap; + +public class openChatting { + + + + public static void main(String[] args) { + + String [] record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"}; + ArrayList answerList = new ArrayList<>(); + + HashMapidMap = new HashMap<>(); + + for(String str : record) { + + String []temp = str.split(" "); + + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Leave")) continue; + + String nick = temp[2]; + + idMap.put(id, nick); + + + } + + for(String str : record) { + + String []temp = str.split(" "); + + String action = temp[0]; + if(action.equals("Change")) continue; + String id = temp[1]; + String nick = idMap.get(id); + + String ans = nick+"님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + } + + String[]answer = new String[answerList.size()]; + + for(int i=0;ivalue) { + map[start][end] = value; + map[end][start] = value; + } + + } + + + int[]dist = new int[n+1]; + + boolean[]visited = new boolean[n+1]; + + visited[1] = true; + + for(int i = 2 ;i<=n;i++) { + dist[i] = (dist[i]==0) ? INF : map[1][i]; + } + + for(int i : dist) System.out.print(i+","); + + System.out.println(); + + for(int i=1;i dist[min_idx] + map[min_idx][j]) { + dist[j] = dist[min_idx] + map[min_idx][j]; + } + + } + + + + } + + for(int i=1;i<=n;i++) { + if(dist[i]<=k)answer++; + } + + + System.out.println(answer); + + for(int i : dist)System.out.print(i+","); + System.out.println(); + for(boolean a : visited)System.out.print(a+","); + System.out.println(); + + } + + +} diff --git a/Basic_Of_Algorithm/src/Today_22_06_03/deliveryAgain.java b/Basic_Of_Algorithm/src/Today_22_06_03/deliveryAgain.java new file mode 100644 index 0000000..b626408 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_03/deliveryAgain.java @@ -0,0 +1,84 @@ +package Today_22_06_03; + +public class deliveryAgain { + + public static void main(String[] args) { + + + int n = 3; + + int [][]road = {{1,2,1},{1,3,5},{2,3,1}}; + + int k = 2; + + int answer = 0; + + int [][] map = new int[n+1][n+1]; + + int INF = 500001; + + for(int i=1;i value) { + map[a][b] = value; + map[b][a] = value; + } + } + + + int[]dist = new int[n+1]; + + for(int i=2 ; i dist[min_idx] + map[min_idx][j]) { + dist[j] = dist[min_idx] + map[min_idx][j]; + } + } + + } + + for(int i = 1 ; i q = new LinkedList<>(); + + 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 newI = move[d][0] + i; + int newJ = move[d][1] + j; + + if(newI<0||newJ<0||maps.length-1 map = new HashMap<>(); + static ArrayList answerList = new ArrayList<>(); + public static void main(String[] args) { + + String []orders = {"ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"}; + int []course = {2,3,4}; + + for(int i=0;i maxList = new ArrayList<>(map.values()); + int max = Collections.max(maxList); + if(max>1) { + for(String key : map.keySet()) { + if(map.get(key)==max) { + answerList.add(key); + } + } + } + } + + map.clear(); + } + + + String[]answer = new String[answerList.size()]; + + Collections.sort(answerList); + + for(int i=0;i " +result.length()); + + + } + + if(answer==Integer.MAX_VALUE) answer=1; + + System.out.println(answer); + + + + } + static String hitProess(int hit) { + return hit>1 ? String.valueOf(hit) : ""; + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_06_09/no_1.java b/Basic_Of_Algorithm/src/Today_22_06_09/no_1.java new file mode 100644 index 0000000..35d3f24 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_09/no_1.java @@ -0,0 +1,97 @@ +package Today_22_06_09; + +import java.util.ArrayList; +import java.util.Collections; + +public class no_1 { + + static int[]apeach; + static int[]ryan; + static boolean[]visited = new boolean[3]; + static char[]op = {'*','+','-'}; + static int max = 0; + static int N; + static ArrayList answerList = new ArrayList<>(); + + public static void main(String[] args) { + + int[] info = {2,1,1,1,0,0,0,0,0,0,0}; + int n = 5; + + N = n; + apeach = info.clone(); + + ryan = new int[apeach.length]; + + dfs(0,0); + + int[]answer; + + if(answerList.isEmpty()) { + answer = new int [] {-1}; + }else { + + Collections.sort(answerList,(o1,o2)-> { + + for(int i=10;i>-1;i--) { + if(o1[i]!=o2[i]) return o1[i]-o2[i]; + } + + return 0; + }); + + + answer = new int[apeach.length]; + + for(int i=0;iapeach[i]) r += 10-i; + else a += 10-i; + + } + + if(r>a) { + int diff = r - a; + if(diff>max) { + max = diff; + answerList.clear(); + answerList.add(ryan.clone()); + }else if(diff==max) { + answerList.add(ryan.clone()); + } + } + + + return; + } + + + + for(int i=0;i<11;i++) { + ryan[i]++; + dfs(i,count+1); + ryan[i]--; + + } + + } +} diff --git a/Basic_Of_Algorithm/src/Today_22_06_09/no_2.java b/Basic_Of_Algorithm/src/Today_22_06_09/no_2.java new file mode 100644 index 0000000..34f9387 --- /dev/null +++ b/Basic_Of_Algorithm/src/Today_22_06_09/no_2.java @@ -0,0 +1,72 @@ +package Today_22_06_09; + +public class no_2 { + + static char[]member = {'A','C','F','J','M','N','R','T'}; + static int answer = 0; + static boolean[ ] visited; + static String[]d; + + public static void main(String[] args) { + + int n = 2; + + String[]data = {"N~F=0", "R~T>2"}; + + d = data.clone(); + + visited = new boolean[member.length]; + + dfs(""); + + System.out.println(answer); + + } + + static boolean check(String now) { + + for(String str : d) { + + int pos1 = now.indexOf(str.charAt(0)); + int pos2 = now.indexOf(str.charAt(2)); + char op = str.charAt(3); + int idx = str.charAt(4)-'0'; + + if(op=='=') { + if(!(Math.abs(pos1-pos2)==idx+1)) return false; + }else if(op=='>') { + if(!(Math.abs(pos1-pos2)>idx+1)) return false; + }else if(op=='=') { + if(!(Math.abs(pos1-pos2) bfs = new LinkedList<>(); + + bfs.add(new int[] {0,0}); + + int [][]move = {{1,0},{0,1},{-1,0},{0,-1}}; + + while(!bfs.isEmpty()) { + + int[]cur = bfs.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-12"}; + + dataSample = data.clone(); + + dfs(""); + + System.out.println(answer); + + } + static boolean check(String now) { + + for(String d : dataSample) { + + int pos1 = now.indexOf(d.charAt(0)); + int pos2 = now.indexOf(d.charAt(2)); + char op = d.charAt(3); + int idx = (d.charAt(4) - '0') + 1; + + if(op=='=') { + if(!(Math.abs(pos1-pos2)==idx)) return false; + }else if(op=='>') { + if(!(Math.abs(pos1-pos2)>idx)) return false; + }else if(op=='<') { + if(!(Math.abs(pos1-pos2)user = new HashMap<>(); + + + for(String str : record) { + + String[]temp = str.split(" "); + + String action =temp[0]; + String id = temp[1]; + + if(action.equals("Leave"))continue; + + user.put(id, temp[2]); + + + } + + ArrayListanswerList = new ArrayList<>(); + + for(String str : record) { + + String[]temp = str.split(" "); + + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Change"))continue; + + String nick = user.get(id); + + String ans = nick +"님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + + } + + + answer = new String[answerList.size()]; + + for(int i=0;i stack = new Stack<>(); + + + for(int mov : moves) { + + mov--; + + for(int i=0;i> singoList = new HashMap<>(); + //나를 신고한 사람 리스트 + HashMap myList = new HashMap<>(); + //내가 받을 매일 횟수 + + for(int i=0;i()); + myList.put(id_list[i], 0); + } + + for(int i=0;i=k) { + + System.out.println(singoList.get(key)); + + for(String str : singoList.get(key)) { + + myList.put(str, myList.get(str)+1); + + + } + } + + } + + for(int i=0;i15) { + new_id = new_id.substring(0,15); + new_id = new_id.replaceAll("[.]$", ""); + } + + if(new_id.length()<3) { + while(new_id.length()<3) { + new_id += new_id.charAt(new_id.length()-1); + } + } + + System.out.println(new_id); + + } +} diff --git a/Basic_Of_Algorithm/src/programmers_level_01/no_3.java b/Basic_Of_Algorithm/src/programmers_level_01/no_3.java new file mode 100644 index 0000000..3b15d80 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_01/no_3.java @@ -0,0 +1,22 @@ +package programmers_level_01; + +public class no_3 { + + public static void main(String[] args) { + + String s = "one4seveneight"; + int answer = 0; + + String [] alpha = {"zero","one","two","three","four","five","six","seven","eight","nine"}; + + + for(int i=0;i stack = new Stack<>(); + + for(int i=0;i fail_rate = new ArrayList<>(); + + int cnt = 0; + + for(int i=1;i<=n;i++) { + for(int j=0;jDouble.compare(b[1], a[1])); + + for(int i=0;i> map = new HashMap<>(); + + for(int i=0;i()); + + map.get(second).add(first); + + } + + + + for(String key : map.keySet()) { + + answer *= map.get(key).size()+1; + } + + + + System.out.println(answer-1); + + + } +} diff --git a/Basic_Of_Algorithm/src/programmers_level_2/no_1.java b/Basic_Of_Algorithm/src/programmers_level_2/no_1.java new file mode 100644 index 0000000..375b4a4 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_1.java @@ -0,0 +1,53 @@ +package programmers_level_2; + +public class no_1 { + + public static void main(String[] args) { + + String s ="abcabcabcabcdededededede"; + + int answer = Integer.MAX_VALUE; + + for(int i=1;i<=s.length()/2;i++) { + + String now = "",next = ""; + String result = ""; + int hit = 1; + for(int j=0;j<=s.length()/i;j++) { + + int start = j * i; + int end = i * (j+1) > s.length() ? s.length() : i * (j+1); + + now = next; + next = s.substring(start,end); + + if(now.equals(next)) { + hit++; + }else { + result += processHit(hit) + now; + hit = 1; + } + + + + + } + + result += processHit(hit) + next; + + System.out.println(result); + + 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/programmers_level_2/no_10.java b/Basic_Of_Algorithm/src/programmers_level_2/no_10.java new file mode 100644 index 0000000..ee3fd67 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_10.java @@ -0,0 +1,55 @@ +package programmers_level_2; + +import java.util.HashMap; +import java.util.ArrayList; + +public class no_10 { + + public static void main(String[] args) { + + + String [] record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"}; + + HashMap map = new HashMap<>(); + ArrayList answerList = new ArrayList<>(); + + for(String str : record) { + + String temp[] = str.split(" "); + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Leave")) continue; + + String nick = temp[2]; + + map.put(id, nick); + + } + + for(String str : record) { + + String temp[] = str.split(" "); + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Change")) continue; + + String nick = map.get(id); + String ans = nick + "님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + } + + + String[]answer = new String[answerList.size()]; + + for(int i = 0 ; i< answerList.size();i++) answer[i] = answerList.get(i); + + for(String str : answer)System.out.println(str); + + + } + +} diff --git a/Basic_Of_Algorithm/src/programmers_level_2/no_11.java b/Basic_Of_Algorithm/src/programmers_level_2/no_11.java new file mode 100644 index 0000000..32904a6 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_11.java @@ -0,0 +1,91 @@ +package programmers_level_2; + +import java.util.ArrayList; +import java.util.Collections; + +public class no_11 { + + public static void main(String[] args) { + + + String m = "CC#BCC#BCC#BCC#B"; + String[]musicinfos = {"03:00,03:30,FOO,CC#B", "04:00,04:08,BAR,CC#BCC#BCC#B"}; + String answer = "(None)"; + + String []mel = {"C#","D#","E#","F#","G#","A#","B#"}; + String []melChange = {"c","d","e","f","g","a","b"}; + + ArrayListanswerList = new ArrayList<>(); + + for(int i=0;i{ + + String []a = o1.split(":"); + String []b = o2.split(":"); + + int aa = Integer.parseInt(a[1]); + int bb = Integer.parseInt(b[1]); + + if(aa>bb) return bb-aa; + + return 0; + }); + + + String [] temp = answerList.get(0).split(":"); + answer = temp[0]; + + System.out.println(answer); + } + + + + + + } + static int change(String start,String end) { + + String s[] = start.split(":"); + + int hour = Integer.parseInt(s[0]); + int StartMin = Integer.parseInt(s[1]) + hour*60; + + s = end.split(":"); + + hour = Integer.parseInt(s[0]); + int endMin = Integer.parseInt(s[1]) + hour*60; + + return endMin - StartMin; + + + + } + +} diff --git a/Basic_Of_Algorithm/src/programmers_level_2/no_12.java b/Basic_Of_Algorithm/src/programmers_level_2/no_12.java new file mode 100644 index 0000000..d16ce0f --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_12.java @@ -0,0 +1,73 @@ +package programmers_level_2; + +public class no_12 { + + public static void main(String[] args) { + + int n = 6; + int[][]road = {{1,2,1},{1,3,2},{2,3,2},{3,4,3},{3,5,2},{3,5,3},{5,6,1}}; + int k = 4; + int answer = 0; + int INF = 500001; + int [][] map = new int[n+1][n+1]; + + for(int i = 1 ; i <=n; i++) { + for(int j=1; j<=n ; j++) { + if(i==j) continue; + map[i][j] = INF; //무한대 + } + } + + + for(int i=0;i w) { + map[a][b] = w; + map[b][a] = w; + } + + } + + int [] dist = new int[n+1]; + for(int i = 2; i <= n ; i++) { + dist[i] = INF; + } + + boolean[] visited = new boolean[n+1]; + visited[1] = true; + + + for(int i=1; i <=n-1 ; i++) { + + int min_idx = 1; + int min_value = INF; + for(int j=2;j<=n;j++) { + if(!visited[j] && dist[j]dist[min_idx] + map[min_idx][j]) { + dist[j] = dist[min_idx] + map[min_idx][j]; + } + } + + } + + for(int i=1;i<=n;i++) { + + if(dist[i]<=k) answer++; + } + System.out.println(answer); + for(int i : dist)System.out.print(i+","); + } + +} \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/programmers_level_2/no_13.java b/Basic_Of_Algorithm/src/programmers_level_2/no_13.java new file mode 100644 index 0000000..ef45464 --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_13.java @@ -0,0 +1,54 @@ +package programmers_level_2; + +import java.util.ArrayList; +import java.util.HashMap; + +public class no_13 { + + + public static void main(String[] args) { + +String [] record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"}; + + HashMap map = new HashMap<>(); + ArrayList answerList = new ArrayList<>(); + + for(String str : record) { + + String temp[] = str.split(" "); + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Leave")) continue; + + String nick = temp[2]; + + map.put(id, nick); + + } + + for(String str : record) { + + String temp[] = str.split(" "); + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Change")) continue; + + String nick = map.get(id); + String ans = nick + "님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + } + + + String[]answer = new String[answerList.size()]; + + for(int i = 0 ; i< answerList.size();i++) answer[i] = answerList.get(i); + + for(String str : answer)System.out.println(str); + + + } +} diff --git a/Basic_Of_Algorithm/src/programmers_level_2/no_14.java b/Basic_Of_Algorithm/src/programmers_level_2/no_14.java new file mode 100644 index 0000000..a6353ea --- /dev/null +++ b/Basic_Of_Algorithm/src/programmers_level_2/no_14.java @@ -0,0 +1,70 @@ +package programmers_level_2; + +public class no_14 { + + public static void main(String[] args) { + + String p = "()))((()"; + + System.out.println(solution(p)); + + } + + static String solution(String p) { + + String answer = change(p); + + + + return 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 answerList = new ArrayList<>(); + + HashMap map = new HashMap<>(); + + for(String str : record) { + + String[]temp = str.split(" "); + + String action = temp[0]; + if(action.equals("Leave")) continue; + String id = temp[1]; + String nick = temp[2]; + + map.put(id, nick); + + } + for(String str : record) { + + String[]temp = str.split(" "); + + String action = temp[0]; + if(action.equals("Change")) continue; + String id = temp[1]; + String nick = map.get(id); + + String ans = nick+"님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + + } + + String[]answer = new String[answerList.size()]; + + + for(int i=0;i2"}; + + + datas = data.clone(); + + boolean[]visited = new boolean[member.length]; + + dfs(visited,""); + + System.out.println(answer); + + } + static void dfs(boolean[]visited,String now) { + + if(now.length()==member.length) { + if(check(now)) answer++; + + return; + } + + + for(int i=0;i') { + if(!(Math.abs(pos1-pos2)>idx+1)) return false; + }else if(ch=='<') { + if(!(Math.abs(pos1-pos2) map = new HashMap<>(); + static ArrayList answerList = new ArrayList<>(); + + public static void main(String[] args) { + + String[] orders = {"ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"}; + int [] course = {2,3,4}; + + for(int i=0;i list = new ArrayList<>(map.values()); + int max = Collections.max(list); + if(max>1) { + for(String key : map.keySet()) { + if(map.get(key)==max) { + answerList.add(key); + } + } + + } + + + + } + + + map.clear(); + } + + String[]answer = new String[answerList.size()]; + + Collections.sort(answerList); + + for(int i=0;i arr1 = new ArrayList<>(); + ArrayList arr2 = new ArrayList<>(); + + + + for(int i=0;i='a'&&first<='z')&&(second>='a'&&second<='z')) { + arr1.add(""+first+second); + } + } + + for(int i=0;i='a'&&first<='z')&&(second>='a'&&second<='z')) { + arr2.add(""+first+second); + } + } + double son = 0; + double mom = 0; + + mom = arr1.size() + arr2.size(); + + System.out.println(mom); + + for(int i=0;i numArr = new ArrayList<>(); + static ArrayList opArr = new ArrayList<>(); + static char[]op = {'+','-','*'}; + static long answer = Integer.MIN_VALUE; + static boolean[]visited = new boolean[3]; + + public static void main(String[] args) { + + String expression = "100-200*300-500+20"; + + change(expression); + + dfs(new char[3] ,0); + + System.out.println(answer); + + } + + static Long changeNum(char ch , long a, long b) { + + if(ch=='+') return a+b; + else if(ch=='*') return a*b; + else if(ch=='-') return a-b; + + return (long) 0; + } + + static void dfs(char[]p,int count) { + + if(count==3) { + + ArrayList numList = new ArrayList<>(numArr); + ArrayList opList = 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/ssafy_avanced_study/no_1226.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java new file mode 100644 index 0000000..524de28 --- /dev/null +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1226.java @@ -0,0 +1,97 @@ +package ssafy_avanced_study; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Queue; +import java.util.LinkedList; + +public class no_1226 { + + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + /* + 여러 개의 테스트 케이스가 주어지므로, 각각을 처리합니다. + */ + + int[][]move = {{1,0},{0,1},{-1,0},{0,-1}}; + + for(int test_case = 1; test_case <= 10; test_case++) + { + + Integer.parseInt(br.readLine()); + + int[][]map = new int[16][16]; + + Queue q = new LinkedList<>(); + + + int []start = new int[2]; + int []end = new int[2]; + + + for(int i=0;i<16;i++) { + String s = br.readLine(); + for(int j=0;j<16;j++) { + map[i][j] = Integer.parseInt(""+s.charAt(j)); + + } + } + + StringBuilder sb = new StringBuilder(); + + boolean[][]visited = new boolean[16][16]; + + + q.add(new int[] {1,1}); + + boolean isTrue = false; + + while(!q.isEmpty()) { + + int [] c = q.poll(); + int i = c[0]; + int j = c[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||15 q = new LinkedList<>(); + + int[][]mov = {{1,0},{0,1},{-1,0},{0,-1}}; + int[][]temp = new int[size][size]; + boolean[][]visited = new boolean[size][size]; + q.add(new int[] {0,0}); + + while(!q.isEmpty()) { + + int []c = q.poll(); + int i = c[0]; + int j = c[1]; + + if(i==size-1 && j==size-1) { + answer = Math.min(answer, temp[i][j]); + continue; + } + if(answer<=temp[i][j]) continue; + + for(int d=0;d<4;d++) { + int ni = i + mov[d][0]; + int nj = j + mov[d][1]; + + if(ni<0 || nj<0|| size-1 temp[i][j] + map[ni][nj]) { + visited[ni][nj] = true; + temp[ni][nj] = temp[i][j] + map[ni][nj]; + q.add(new int[] {ni,nj}); + } + + } + + } + + System.out.println("#"+test_case+" "+answer); + + + + } + + } + +} \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java new file mode 100644 index 0000000..5741327 --- /dev/null +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1249.java @@ -0,0 +1,79 @@ +package ssafy_avanced_study; + + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Queue; +import java.util.LinkedList; + +public class no_1249 { + + + + + public static void main(String args[]) throws Exception + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T; + T=Integer.parseInt(br.readLine()); + + for(int test_case = 1; test_case <= T; test_case++){ + + int size =Integer.parseInt(br.readLine()); + + int[][]map = new int[size][size]; + + int answer = Integer.MAX_VALUE; + + + for(int i=0;i q = new LinkedList<>(); + + int[][]mov = {{1,0},{0,1},{-1,0},{0,-1}}; + int[][]temp = new int[size][size]; + boolean[][]visited = new boolean[size][size]; + q.add(new int[] {0,0}); + + while(!q.isEmpty()) { + + int []c = q.poll(); + int i = c[0]; + int j = c[1]; + + if(i==size-1 && j==size-1) { + answer = Math.min(answer, temp[i][j]); + continue; + } + if(answer<=temp[i][j]) continue; + + for(int d=0;d<4;d++) { + int ni = i + mov[d][0]; + int nj = j + mov[d][1]; + + if(ni<0 || nj<0|| size-1 temp[i][j] + map[ni][nj]) { + visited[ni][nj] = true; + temp[ni][nj] = temp[i][j] + map[ni][nj]; + q.add(new int[] {ni,nj}); + } + + } + + } + + System.out.println("#"+test_case+" "+answer); + + + + } + + } + + } \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1936.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1936.java new file mode 100644 index 0000000..a89a8df --- /dev/null +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1936.java @@ -0,0 +1,37 @@ +package ssafy_avanced_study; + +import java.util.Scanner; + +public class no_1936 { + + + public static void main(String[] args) { + + Scanner scan = new Scanner(System.in); + + int a = scan.nextInt(); + int b = scan.nextInt(); + + String.valueOf(a); + + String answer = ""; + + if(a==1){ + if(b==2) answer = "B"; + else answer = "A"; + }else if(a==2){ + if(b==3) answer = "B"; + else answer = "A"; + }else{ + if(b==1) answer = "B"; + else answer = "A"; + } + ///////////////////////////////////////////////////////////////////////////////////////////// + /* + 이 부분에 여러분의 알고리즘 구현이 들어갑니다. + */ + ///////////////////////////////////////////////////////////////////////////////////////////// + System.out.println(answer); + + } +} diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1946.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1946.java new file mode 100644 index 0000000..4721da0 --- /dev/null +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1946.java @@ -0,0 +1,60 @@ +package ssafy_avanced_study; + +import java.util.Scanner; + +public class no_1946 { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T; + T=sc.nextInt(); + + + for(int test_case = 1; test_case <= T; test_case++) + { + + + int n = sc.nextInt(); + + + + String answer = ""; + + sc.nextLine(); + + for(int i=0;i3) { + count = Integer.parseInt(""+str.charAt(2)+str.charAt(3)); + }else if(str.charAt(2)=='2' && str.length()>3) { + count = Integer.parseInt(""+str.charAt(2)+str.charAt(3)); + } + else count = Integer.parseInt(String.valueOf(str.charAt(2))); + + for(int j=0;j-1;i--) { + map1[j][size-i-1] = map[i][j]; + } + + } + + int[][]map2 = new int[size][size]; + + + for(int i=size-1;i>-1;i--) { + for(int j=size-1;j>-1;j--) { + map2[size-i-1][size-j-1] = map[i][j]; + } + + } + + int[][]map3 = new int[size][size]; + + for(int j=size-1;j>-1;j--) { + for(int i=0;i1 || arr2[map[i][j]-1]>1) { + flag = false; + break outerLoop; + } + + + } + + } + outerLoop: + for(int l=0;l<3;l++) { + + int[]arr = new int[9]; + + for(int i=0;i<3;i++) { + for(int j=0;j<3;j++) { + arr[map[i+(l*3)][j+(l*3)]-1]++; + if(arr[map[i][j]-1]>1) { + flag = false; + break outerLoop; + } + + } + } + } + + + if(!flag) answer += 0 ; + else answer += 1; + + System.out.println(answer); + + + + } + } +} \ No newline at end of file diff --git a/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1979.java b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1979.java new file mode 100644 index 0000000..bf7f756 --- /dev/null +++ b/Basic_Of_Algorithm/src/ssafy_avanced_study/no_1979.java @@ -0,0 +1,108 @@ +package ssafy_avanced_study; + +import java.util.Scanner; +import java.util.Stack; + +public class no_1979 { + + public static void main(String[] args) { + + + Scanner sc = new Scanner(System.in); + int T; + T=sc.nextInt(); + + for(int test_case = 1; test_case <= T; test_case++){ + + String answer = "#"+test_case+" "; + + int size = sc.nextInt(); + int len = sc.nextInt(); + int ans = 0; + + int [][]map = new int[size][size]; + + for(int i=0;i stack = new Stack<>(); + for(int j=0;j stack = new Stack<>(); + for(int i=0;i=arr.length) break; + + + } + + + }else { + + if(arr[loc]==0) arr[loc] = 1; + else arr[loc] = 0; + + int left = loc-1; + int right = loc+1; + + while(true) { + + if(left<1 || arr.length q= new LinkedList<>(); + + q.add(new int[] {0,0}); + + int[][]temp = new int[maps.length][maps[0].length]; + + temp[0][0] = 1; + + int[][]move = {{1,0},{0,1},{-1,0},{0,-1}}; + + 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>infoMap = 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[]answer = new int[query.length]; + + + + for(String str : info) { + + String[]temp = str.split(" "); + dfs(temp,0,""); + + } + + for(int i=0;i list = new ArrayList<>(infoMap.get(temp[0])); + + Collections.sort(list); + + int start = 0; + int end = list.size()-1; + int score = Integer.parseInt(temp[1]); + + + + while(start<=end) { + + int mid = (start+end)/2; + + if(score>list.get(mid)) start = mid+1; + else end = mid-1; + + } + + + return list.size()-start; + } + + static void dfs(String[]temp,int count,String now) { + + if(count==4) { + if(!infoMap.containsKey(now)) { + infoMap.put(now, new ArrayList()); + } + infoMap.get(now).add(Integer.parseInt(temp[4])); + return; + } + + dfs(temp,count+1,now+temp[count]); + dfs(temp,count+1,now+"-"); + + + + } + +} diff --git a/Basic_Of_Algorithm/src/test/color.java b/Basic_Of_Algorithm/src/test/color.java new file mode 100644 index 0000000..52513e6 --- /dev/null +++ b/Basic_Of_Algorithm/src/test/color.java @@ -0,0 +1,81 @@ +package test; + +public class color { + + public static void main(String[] args) { + + String[]temp = {"RRRBB", + "GGBBB", + "BBBRR", + "BBRRR", + "RRRRR"}; + + char[][]map = new char[temp.length][temp[0].length()]; + + + for(int i=0;i map = new HashMap<>(); + ArrayList answerList = new ArrayList<>(); + + for(String str : record) { + + String temp[] = str.split(" "); + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Leave")) continue; + + String nick = temp[2]; + + map.put(id, nick); + + } + + for(String str : record) { + + String temp[] = str.split(" "); + String action = temp[0]; + String id = temp[1]; + + if(action.equals("Change")) continue; + + String nick = map.get(id); + String ans = nick + "님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + + } + + + String[]answer = new String[answerList.size()]; + + for(int i = 0 ; i< answerList.size();i++) answer[i] = answerList.get(i); + + for(String str : answer)System.out.println(str); + + + } +} diff --git a/Basic_Of_Algorithm/src/test/openChatting.java b/Basic_Of_Algorithm/src/test/openChatting.java new file mode 100644 index 0000000..a68d28c --- /dev/null +++ b/Basic_Of_Algorithm/src/test/openChatting.java @@ -0,0 +1,52 @@ +package test; + +import java.util.HashMap; +import java.util.ArrayList; + +public class openChatting { + + public static void main(String[] args) { + + String[]record = {"Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234","Enter uid1234 Prodo","Change uid4567 Ryan"}; + + HashMap map = new HashMap<>(); + + ArrayList answerList = new ArrayList<>(); + + for(String str : record) { + + String []temp = str.split(" "); + + String action = temp[0]; + String id = temp[1]; + if(action.equals("Leave"))continue; + String nick = temp[2]; + + map.put(id, nick); + + } + + + for(String str : record) { + + String []temp = str.split(" "); + + String action = temp[0]; + String id = temp[1]; + if(action.contains("Change"))continue; + String nick = map.get(id); + + String ans = nick+"님이 " + (action.equals("Enter") ? "들어왔습니다." : "나갔습니다."); + + answerList.add(ans); + } + + String[]answer = new String[answerList.size()]; + + for(int i=0;i map = new HashMap<>(); + TreeMap tree = new TreeMap<>(); + + for(String s : records) { + + String []temp = s.split(" "); + int time = timeChange(temp[0]); + String num = temp[1]; + String action = temp[2]; + + if(action.equals("IN")) { + if(!tree.containsKey(num)) tree.put(num, 0); + map.put(num, time); + } + else { + + tree.put(num, tree.get(num) + (time - map.get(num))); + map.remove(num); + } + } + + if(!map.isEmpty()) { + for(String key : map.keySet()) { + tree.put(key, tree.get(key) + (23*60+59) - map.get(key)); + + } + } + + ArrayListanswerList = new ArrayList<>(); + + for(String key : tree.keySet()) { + + double time = tree.get(key); + + if(time<=fees[0]) { + answerList.add(fees[1]); + }else { + time = time - fees[0]; + double cal = time/fees[2]; + int extraTime = (int) Math.ceil(cal); + int fee = (extraTime * fees[3]) + fees[1]; + answerList.add(fee); + } + } + + int[]answer = new int[answerList.size()]; + for(int i=0;i0) { + x=time; + for(int i=y; i=time; i--) { + map[i][x] = value--; + } + + y=time; + for(int i=x-1; i>time; i--) { + map[y][i] = value--; + } + time++; + limit--; + y=time; + } + + StringBuilder sb = new StringBuilder(); + int tx=0, ty=0; + for(int i=0; i-1;i--) { + l += i; + } + + if(l==m) System.out.println("이게 귀납법"); + + System.out.println(l); + System.out.println(m); + } + + static int test(int n) { + + if(n==0) return n; + return n+test(n-1); + + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..8376b04 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Basic_Of_Algorithm +알고리즘 기초 예제 및 테스트