├── study-2nd ├── level1 │ ├── seungjin │ │ ├── readme.md │ │ ├── Soultion02.java │ │ └── Soultion01.java │ ├── seungju │ │ ├── solution02.js │ │ └── solution01.js │ ├── jiwon │ │ ├── solution1.js │ │ └── solution2.js │ ├── jihye │ │ ├── Solution02.java │ │ └── Solution01.java │ ├── yongseong │ │ ├── Solution02.js │ │ └── Solution01.js │ └── yunji │ │ ├── Solution02.kt │ │ └── Solution01.kt ├── level2 │ ├── seungjin │ │ ├── solution02.java │ │ ├── solution01.java │ │ └── page_rank.py │ ├── seungju │ │ ├── solution01.js │ │ └── solution02.js │ ├── jiwon │ │ ├── solution1.js │ │ └── solution2.js │ ├── yunji │ │ ├── Solution01.java │ │ └── Solution02.java │ ├── jihye │ │ └── Solution1.java │ └── yongseong │ │ ├── Solution01.js │ │ └── Solution02.js └── level3 │ ├── jihye │ ├── Solution02.java │ └── Solution01.java │ ├── Solution01.java │ ├── seungju │ ├── solution01.js │ └── solution02.js │ └── Solution02.java ├── .editorconfig ├── study-1st ├── team1 │ ├── Search │ │ ├── dongkun │ │ │ ├── search-4.py │ │ │ ├── search-2.py │ │ │ ├── search-1.py │ │ │ └── search-3.py │ │ └── byeongguk │ │ │ ├── Solution01.py │ │ │ └── Solution02.py │ ├── Sort │ │ ├── jihun │ │ │ └── Solution01.py │ │ ├── byeongguk │ │ │ ├── Solution01.py │ │ │ └── Solution02.py │ │ ├── dongkun │ │ │ ├── BigNumber.py │ │ │ └── KNumber.py │ │ └── jiwon │ │ │ └── solution1.py │ ├── Hash │ │ ├── jihun │ │ │ ├── Solution01.py │ │ │ ├── Solution03.py │ │ │ ├── Solution02.py │ │ │ └── Solution04.py │ │ ├── jiwon │ │ │ ├── solution1.py │ │ │ └── solution2.py │ │ └── byeongguk │ │ │ ├── Solution02.py │ │ │ ├── Solution01.py │ │ │ ├── Solution03.py │ │ │ └── Solution04.py │ └── BF │ │ ├── jihun │ │ ├── Solution04.py │ │ ├── Solution01.py │ │ ├── Solution03.py │ │ └── Solution02.py │ │ └── jiwon │ │ ├── Solution01.py │ │ └── Solution02.py ├── team2 │ ├── DFS │ │ ├── Seungjin │ │ │ ├── Solution2.md │ │ │ ├── Solution01.java │ │ │ └── Solution03.java │ │ ├── Hyungsuk │ │ │ ├── tower.js │ │ │ ├── iron-bar.js │ │ │ └── printer.js │ │ ├── jihye │ │ │ └── Solution01.java │ │ ├── juhyun │ │ │ └── Solution01.java │ │ ├── Shinje │ │ │ └── WordChange.java │ │ ├── sangeun │ │ │ ├── Network.java │ │ │ └── Word.java │ │ └── yunji │ │ │ ├── Solution03.java │ │ │ └── Solution01.java │ ├── Search │ │ └── Hyungsuk │ │ │ ├── carpet.js │ │ │ └── test-score.js │ ├── Stack │ │ ├── Seungjin │ │ │ ├── Solution05.java │ │ │ └── Solution01.java │ │ ├── Shinje │ │ │ ├── Tower.java │ │ │ ├── IronBar.java │ │ │ └── Printer.java │ │ ├── sangeun │ │ │ ├── Top.java │ │ │ ├── StockPrice.java │ │ │ ├── Printer.java │ │ │ ├── FunctionDevelop.java │ │ │ └── Bridge.java │ │ ├── juhyun │ │ │ ├── Solution01.java │ │ │ ├── Solution03.java │ │ │ └── Solution02.java │ │ └── yunji │ │ │ ├── Solution02.java │ │ │ └── Solution01.java │ └── BruteForce │ │ ├── Shinje │ │ ├── PrimeNumber.java │ │ └── PreTest.java │ │ ├── sangeun │ │ ├── Carpet.java │ │ ├── NumberBaseball.java │ │ └── Test.java │ │ ├── juhyun │ │ ├── Solution04.java │ │ ├── Solution01.java │ │ └── Solution02.java │ │ ├── haeseong │ │ ├── 카펫.java │ │ ├── 모의고사.java │ │ └── 소수_찾기.java │ │ └── yunji │ │ ├── Solution01.java │ │ ├── Solution02.java │ │ └── Solution03.java ├── team1-status.md ├── team2-status.md └── README.md ├── attendance.md └── README.md /study-2nd/level1/seungjin/readme.md: -------------------------------------------------------------------------------- 1 | safasd 2 | -------------------------------------------------------------------------------- /study-2nd/level2/seungjin/solution02.java: -------------------------------------------------------------------------------- 1 | 브루트포스 2 | -------------------------------------------------------------------------------- /study-2nd/level1/seungju/solution02.js: -------------------------------------------------------------------------------- 1 | function solution(x, n) { 2 | // [1, 2, 3, ..., n] -> [1 * x, 2 * x, ..., n * x] 3 | return Array(n).fill().map((_, i) => (i + 1) * x) 4 | } 5 | 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | trim_trailing_whitespace = true 8 | 9 | [*.{py}] 10 | indent_size = 4 11 | indent_style = space 12 | -------------------------------------------------------------------------------- /study-1st/team1/Search/dongkun/search-4.py: -------------------------------------------------------------------------------- 1 | # 주어진 숫자의 부분집합 각각의 Permutation을 모두 소수 검사를 하면 될 것 같습니다. 2 | # 하지만 파이썬에서 제공하는 permutation 함수를 쓰지 않고 구현하려니 어려움이 있습니다. 3 | def solution(numbers): 4 | answer = 0 5 | return answer -------------------------------------------------------------------------------- /study-1st/team1/Sort/jihun/Solution01.py: -------------------------------------------------------------------------------- 1 | def solution(array, commands): 2 | answer = [] 3 | for cms in commands: 4 | l = sorted(array[cms[0]-1:cms[1]]) 5 | answer.append(l[cms[2]-1]) 6 | 7 | return answer 8 | -------------------------------------------------------------------------------- /study-2nd/level1/seungju/solution01.js: -------------------------------------------------------------------------------- 1 | function solution(s){ 2 | 3 | // Regex count 4 | var pCount = (s.match(/[pP]/g) || []).length; 5 | var yCount = (s.match(/[yY]/g) || []).length; 6 | 7 | return pCount == yCount; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /study-1st/team1/Hash/jihun/Solution01.py: -------------------------------------------------------------------------------- 1 | def solution(participant, completion): 2 | d = {} 3 | for c in completion: 4 | d[c] = d.get(c, 0) + 1 5 | 6 | for p in participant: 7 | if d.get(p, 0) == 0: 8 | return p 9 | d[p] = d.get(p) - 1 10 | -------------------------------------------------------------------------------- /study-2nd/level1/jiwon/solution1.js: -------------------------------------------------------------------------------- 1 | function solution(s){ 2 | if(s.match(/p/gi).length == s.match(/y/gi).length){ 3 | return true; 4 | }else if(s.match(/p/gi).length && s.match(/y/gi).length == 0){ 5 | return true; 6 | }else{ 7 | return false; 8 | } 9 | } -------------------------------------------------------------------------------- /study-2nd/level1/jiwon/solution2.js: -------------------------------------------------------------------------------- 1 | function solution(n) { 2 | var result = []; 3 | 4 | for(var i = 1; i <= n; i++){ 5 | if(i%2 == 1){ 6 | result += "수"; 7 | }else{ 8 | result += "박"; 9 | } 10 | } 11 | return result; 12 | } -------------------------------------------------------------------------------- /study-1st/team1/Hash/jihun/Solution03.py: -------------------------------------------------------------------------------- 1 | def solution(clothes): 2 | d = {} 3 | for clothe in clothes: 4 | d[clothe[1]] = d.get(clothe[1], 1) + 1 5 | 6 | answer = 1 7 | for count in d.values(): 8 | answer = answer * count 9 | 10 | return answer - 1 11 | -------------------------------------------------------------------------------- /study-1st/team1/BF/jihun/Solution04.py: -------------------------------------------------------------------------------- 1 | def solution(brown, red): 2 | lec = brown + red 3 | for r in range(1, red // 2 + 2): 4 | if red % r == 0: 5 | for b in range(r + 2, brown // 2 + 2): 6 | if lec % b == 0 and lec // b > red // r + 1: 7 | return [lec // b, b] 8 | -------------------------------------------------------------------------------- /study-2nd/level1/jihye/Solution02.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | class Solution { 4 | public String solution(String[] seoul) { 5 | String answer = ""; 6 | 7 | int x = Arrays.asList(seoul).indexOf("Kim"); 8 | answer = "김서방은 " + x + "에 있다"; 9 | 10 | 11 | return answer; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /study-1st/team1/Sort/byeongguk/Solution01.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | def solution(array, commands): 5 | answer = [] 6 | 7 | for command in commands: 8 | temp = sorted(array[command[0] - 1:command[1]]) 9 | answer.append(temp[command[2] - 1]) 10 | 11 | return answer 12 | -------------------------------------------------------------------------------- /study-1st/team1/Sort/dongkun/BigNumber.py: -------------------------------------------------------------------------------- 1 | from functools import cmp_to_key 2 | 3 | def sortFunction(n1,n2): 4 | return int(str(n1)+str(n2))-int(str(n2)+str(n1)) 5 | 6 | def solution(numbers): 7 | sortedNumbers = [str(n) for n in sorted(numbers, key=cmp_to_key(sortFunction), reverse=True)] 8 | return str(int("".join(sortedNumbers))) -------------------------------------------------------------------------------- /study-1st/team1/Sort/dongkun/KNumber.py: -------------------------------------------------------------------------------- 1 | def solution(array, commands): 2 | answer = [] 3 | for command in commands: 4 | start = command[0] - 1 5 | end = command[1] - 1 6 | sliced = array[start:end+1] 7 | sortedList = sorted(sliced) 8 | answer.append(sortedList[command[2]-1]) 9 | return answer -------------------------------------------------------------------------------- /study-1st/team1/Hash/jiwon/solution1.py: -------------------------------------------------------------------------------- 1 | def solution(participant, completion): 2 | participant.sort() 3 | completion.sort() 4 | for i in range(len(completion)): 5 | if completion[i] != participant[i]: 6 | return participant[i] 7 | elif completion[i] == completion[-1:][0]: 8 | return participant[i+1] 9 | -------------------------------------------------------------------------------- /study-2nd/level1/seungjin/Soultion02.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public long solution(int a, int b) { 3 | long answer = 0; 4 | 5 | if(a > b){ 6 | int temp = a; 7 | a = b; 8 | b = temp; 9 | } 10 | 11 | 12 | answer = (b*(b+1)/2) - (a*(a-1)/2); 13 | 14 | return answer; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /study-1st/team1/Sort/byeongguk/Solution02.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | from functools import cmp_to_key 5 | 6 | def solution(numbers): 7 | numbers = list(map(str, numbers)) 8 | numbers.sort(key=cmp_to_key(lambda x, y: int(y + x) - int(x + y))) 9 | 10 | return ''.join(numbers) if numbers[0] != '0' else '0' 11 | -------------------------------------------------------------------------------- /study-1st/team2/DFS/Seungjin/Solution2.md: -------------------------------------------------------------------------------- 1 | 1. 우선 단어간에 서로 바꿀수있는지를 체크하는 플래그를 만듭니다 2 | 3 | float not_change[] 4 | 5 | 6 | 2. 비트연산자를 이용해서로 이동이 불가능한 인덱스를 위의 배열에 쉬프트 연산자 or 연산자 조합을 통해 저장합니다 7 | 8 | 9 | 3. 큐를 이용해 BFS 구조를 만들고 10 | Pop을 해서 얻은 값들을 End값과 비교하여 End비교 값이 참인순간 바로 값을 반환합니다. 그렇지 않으면 비트연산 and 비교 값을 통해 각 시작점을 for문으로 Push 합니다. 11 | 12 | 만일 이렇게 해서 답이 안나오면 X 13 | -------------------------------------------------------------------------------- /study-2nd/level1/yongseong/Solution02.js: -------------------------------------------------------------------------------- 1 | function solution(x, n) { 2 | var numbers = []; 3 | const plusNumber = x; 4 | // n만큼 반복합니다. 5 | for ( var i = 0; i < n; i++ ) { 6 | // x를 배열에 삽입합니다. 7 | numbers.push(x); 8 | // x를 증가시킵니다. 9 | x += plusNumber; 10 | } 11 | // 배열을 리턴합니다. 12 | return numbers; 13 | } 14 | -------------------------------------------------------------------------------- /study-2nd/level1/yongseong/Solution01.js: -------------------------------------------------------------------------------- 1 | function solution(phoneNumber) { 2 | // 전화번호 뒷 4자리를 추출합니다. 3 | const backFourNumber = phoneNumber.slice(phoneNumber.length - 4); 4 | // 전화번호 길이만큼 *를 생성합니다. 5 | var star = ''; 6 | for ( var i = 0; i < phoneNumber.length - 4; i++ ) { 7 | star += '*'; 8 | } 9 | // *와 뒷 4자리 더한 값을 리턴합니다. 10 | return star + backFourNumber; 11 | } 12 | -------------------------------------------------------------------------------- /study-2nd/level1/yunji/Solution02.kt: -------------------------------------------------------------------------------- 1 | class Solution02 { 2 | fun solution(n: Long): Long { 3 | var answer = 1L 4 | var multi = answer * answer 5 | 6 | while (multi <= n) { 7 | if (multi == n) 8 | return (answer + 1) * (answer + 1) 9 | 10 | answer++ 11 | multi = answer * answer 12 | } 13 | 14 | return -1 15 | } 16 | } -------------------------------------------------------------------------------- /study-1st/team1/Hash/byeongguk/Solution02.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | def solution(phone_book): 5 | numbers = list() 6 | 7 | for phone in phone_book: 8 | for number in numbers: 9 | if phone.startswith(number) or number.startswith(phone): 10 | return False 11 | 12 | numbers.append(phone) 13 | 14 | return True 15 | -------------------------------------------------------------------------------- /study-2nd/level1/seungjin/Soultion01.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[][] solution(int[][] arr1, int[][] arr2) { 3 | int[][] answer = {}; 4 | answer = new int[arr1.length][arr1[0].length]; 5 | 6 | for(int i=0; i < arr1.length; i++){ 7 | for(int j=0; j< arr1[0].length; j++) 8 | answer[i][j] = arr1[i][j] + arr2[i][j]; 9 | } 10 | 11 | 12 | return answer; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /attendance.md: -------------------------------------------------------------------------------- 1 | # 스터디 진행 현황 2 | 3 | 스터디 진행 현황입니다. 4 | 5 | ## 출석 체크 6 | 7 | | |윤지|지혜|승진|지원|승주|용성| 8 | |---|---|---|---|---|---|---| 9 | |1주차(5/18)|O |O |O |O |O |O | 10 | |2주차(5/25)|O |O |O |O |O |O | 11 | |3주차(6/1)|O |O |O |O |O |O | 12 | |4주차(6/8)|O |O |x |O |O |O | 13 | 14 | > 너무나 완벽한 출석률 15 | 16 | ## 벌금 내역 17 | - 3주차 : 15,000원 18 | - 4주차 : 30,000원 19 | - 총합 : 45,000원 20 | - 결산 : 오설록 롤케이크 + 스타벅스로 다함께 잘 먹었습니다. 21 | -------------------------------------------------------------------------------- /study-2nd/level2/seungju/solution01.js: -------------------------------------------------------------------------------- 1 | function solution(s) { 2 | // Split string s with whitespace, then sort by numeric values 3 | const sortedNumbers = s.split(' ') 4 | .sort((lhs, rhs) => lhs - rhs); 5 | 6 | // Since the array is sorted, take the first/last element 7 | const minimum = sortedNumbers.shift(); 8 | const maximum = sortedNumbers.pop(); 9 | 10 | return minimum + ' ' + maximum 11 | } -------------------------------------------------------------------------------- /study-1st/team2/DFS/Hyungsuk/tower.js: -------------------------------------------------------------------------------- 1 | function solution(heights) { 2 | let heightsLength = heights.length; 3 | let answer = new Array(heightsLength).fill(0); 4 | for(let i = heightsLength - 1; i >= 0; i--) { 5 | for(let j = i - 1; j >= 0; j--) { 6 | if(heights[j] > heights[i]) { 7 | answer[i] = j + 1; 8 | break; 9 | } 10 | } 11 | } 12 | return answer; 13 | } 14 | -------------------------------------------------------------------------------- /study-1st/team2/Search/Hyungsuk/carpet.js: -------------------------------------------------------------------------------- 1 | function solution(brown, red) { 2 | let sum = brown + red; 3 | let divisorCouples = []; 4 | for(let i = Math.floor(Math.sqrt(sum)); i >= 1; i--) { 5 | if(sum % i === 0) { 6 | divisorCouples.push([sum / i, i]); 7 | } 8 | } 9 | return divisorCouples.find(divisorCouple => { 10 | return (divisorCouple[0] + divisorCouple[1] - 2) * 2 === brown; 11 | }); 12 | } -------------------------------------------------------------------------------- /study-1st/team1/Search/dongkun/search-2.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def solution(brown, red): 4 | end = int(math.sqrt(red)) 5 | for i in range(1,end+1): 6 | if red % i == 0: 7 | width = int(red/i) 8 | height = i 9 | needBrown = (width + height)*2 + 4 10 | if needBrown == brown: 11 | return [width + 2, height + 2] 12 | 13 | print(solution(10,2)) 14 | print(solution(8,1)) 15 | print(solution(24,24)) -------------------------------------------------------------------------------- /study-1st/team1/Hash/byeongguk/Solution01.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | from collections import Counter 5 | 6 | def solution(participant, completion): 7 | participant_dict = Counter(participant) 8 | 9 | for comp in completion: 10 | if comp in participant_dict: 11 | participant_dict[comp] -= 1 12 | 13 | for person, count in participant_dict.items(): 14 | if count != 0: 15 | return person 16 | -------------------------------------------------------------------------------- /study-2nd/level2/jiwon/solution1.js: -------------------------------------------------------------------------------- 1 | function solution(n) { 2 | var answer = 0; 3 | 4 | if(n>2){ 5 | answer = (n-2) + (n-1); 6 | if(answer == 3){ 7 | answer = answer - 1; 8 | }else if(answer > 3){ 9 | answer = answer - 2; 10 | } 11 | }else if(n<=2){ 12 | answer = 1; 13 | }else{ 14 | return n; 15 | } 16 | 17 | answer = Math.round(answer%1234567); 18 | return answer; 19 | } -------------------------------------------------------------------------------- /study-1st/team1-status.md: -------------------------------------------------------------------------------- 1 | # 스터디 진행 현황 2 | 3 | 1팀의 스터디 진행 현황입니다. (팀장: 공병국님) 4 | 5 | ## 출석 체크 6 | 7 | | |병국|지원|지훈|동건|유경|지은| 8 | |---|---|---|---|---|---|---| 9 | |1주차(3/23)|X |O |O |O |O |O | 10 | |2주차(3/30)|O |O |X |X |O |O | 11 | |3주차(4/6)|X |O |O |O |O |X | 12 | |4주차(4/13)|O |O |O |X |O |O | 13 | 14 | ## 벌금 내역 15 | 16 | 1. 총액 : 10,000원 17 | 2. 상세 내역 18 | * 1주차 납부자 : 없음 19 | * 2주차 납부자 : 없음 20 | * 3주차 납부자 : 병국 (총 5,000원) 21 | * 4주차 납부자 : 동건 (총 5,000원) 22 | -------------------------------------------------------------------------------- /study-1st/team1/Hash/jihun/Solution02.py: -------------------------------------------------------------------------------- 1 | def solution(phone_book): 2 | for i, num1 in enumerate(phone_book): 3 | for j in range(i + 1, len(phone_book)): 4 | num2 = phone_book[j] 5 | if len(num1) < len(num2): 6 | s = num1 7 | l = num2 8 | else: 9 | s = num2 10 | l = num1 11 | 12 | if l.startswith(s): 13 | return False 14 | 15 | return True 16 | -------------------------------------------------------------------------------- /study-1st/team2-status.md: -------------------------------------------------------------------------------- 1 | # 스터디 진행 현황 2 | 2팀의 스터디 진행 현황입니다. 3 | 4 | ## 출석체크 5 | | |윤지|상은|승진|지혜|신제|형석|주현| 6 | |---|---|---|---|---|---|---|---| 7 | |1주차(3/23)|O |O |O |O |O |O |O | 8 | |2주차(3/30)|O |O |X |O |O |X |O | 9 | |3주차(4/6)|O |O |O |O |O |O |O | 10 | |4주차(4/13)|O |X |O |X |X |X |X | 11 | 12 | ## 벌금 내역 13 | 1. 총액 : 40,000원 14 | 2. 상세 내역 15 | * 1주차 납부자 : 없음 16 | * 2주차 납부자 : 없음 17 | * 3주차 납부자 : 윤지, 신제, 지혜, 승진 (총 20,000원) 18 | * 4주차 납부자 : 지혜, 승진, 신제, 형석 (총 20,000원) 19 | -------------------------------------------------------------------------------- /study-1st/team1/Search/dongkun/search-1.py: -------------------------------------------------------------------------------- 1 | def solution(answers): 2 | list = [[1, 2, 3, 4, 5], [2, 1, 2, 3, 2, 4, 2, 5], [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]] 3 | checks = [0,0,0] 4 | for idx, answer in enumerate(answers): 5 | for i in range(3): 6 | checks[i] += 1 if list[i][idx%len(list[i])] == answer else 0 7 | answer = [idx + 1 for idx,check in enumerate(checks) if check == max(checks)] 8 | return answer 9 | 10 | print(solution([1,2,3,4,5])) 11 | print(solution([1,3,2,4,2])) -------------------------------------------------------------------------------- /study-1st/team2/Stack/Seungjin/Solution05.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | class Solution { 4 | public int[] solution(int[] heights) { 5 | int [] answer = new int [heights.length]; 6 | Arrays.fill(answer, 0); 7 | 8 | for(int i=0; i=0; j--) { 10 | if(heights[j]>heights[i]) { 11 | answer[i] = j+1; 12 | break; 13 | } 14 | } 15 | } 16 | 17 | return answer; 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /study-2nd/level2/yunji/Solution01.java: -------------------------------------------------------------------------------- 1 | public class Solution01 { 2 | static boolean solution(String s) { 3 | int leftSide = 0, rightSide = 0; 4 | char[] input = s.toCharArray(); 5 | for (char c : input) { 6 | if (c == '(') { 7 | leftSide++; 8 | } else { 9 | rightSide++; 10 | } 11 | 12 | if (rightSide > leftSide) return false; 13 | } 14 | 15 | return (leftSide == rightSide); 16 | } 17 | } -------------------------------------------------------------------------------- /study-1st/team2/Stack/Shinje/Tower.java: -------------------------------------------------------------------------------- 1 | class Tower { 2 | public int[] solution(int[] heights) { 3 | int[] answer = new int[heights.length]; 4 | Stack stack = new Stack(); 5 | int len = heights.length; 6 | 7 | for (int i = 0; i < len; i++) { 8 | stack.push(heights[i]); 9 | } 10 | 11 | for (int i = len - 1; i >= 0; i--) { 12 | if (heights[i] > stack.peek()) { 13 | answer[i] = i + 1; 14 | stack.pop(); 15 | } else { 16 | answer[i] = 0; 17 | } 18 | } 19 | 20 | return answer; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /study-1st/team1/BF/jihun/Solution01.py: -------------------------------------------------------------------------------- 1 | def solution(answers): 2 | guesses = [ 3 | [1, 2, 3, 4, 5], 4 | [2, 1, 2, 3, 2, 4, 2, 5], 5 | [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]] 6 | 7 | cor = [0, 0, 0] 8 | for idx, ans in enumerate(answers): 9 | for i in range(3): 10 | if guesses[i][idx%len(guesses[i])] == ans: 11 | cor[i] += 1 12 | 13 | m = max(cor) 14 | answer = [] 15 | for i, c in enumerate(cor): 16 | if c == m: 17 | answer.append(i + 1) 18 | 19 | return answer 20 | -------------------------------------------------------------------------------- /study-1st/team1/Hash/jiwon/solution2.py: -------------------------------------------------------------------------------- 1 | def solution(phone_book): 2 | f = 0 3 | pb = phone_book.copy() 4 | for i in range(len(pb)): 5 | del pb[i] 6 | for number in pb: 7 | if phone_book[i] in number: 8 | print(phone_book[i], number) 9 | f += 1 10 | pb = phone_book.copy() 11 | if f !=0 : 12 | return False 13 | else: 14 | return True 15 | 16 | a = ['12','123','1235','567','88'] 17 | print(solution(a)) 18 | 19 | # 코드가 효율적이지 않은건 알겠는데 정확성이 왜 60밖에 안나오는지 모르겠어요 ㅠ ㅠ 20 | # 입출력예제는 다 맞습니다 21 | -------------------------------------------------------------------------------- /study-1st/team1/Hash/byeongguk/Solution03.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | def solution(clothes): 5 | combi = 1 6 | cloth_list = [] 7 | cloth_dict = {} 8 | 9 | for _, parts in clothes: 10 | if parts not in cloth_dict: 11 | cloth_dict[parts] = 0 12 | cloth_dict[parts] += 1 13 | 14 | 15 | cloth_list = list(cloth_dict.values()) 16 | 17 | if len(cloth_list) == 1: 18 | return combi * cloth_list[0] 19 | 20 | for count in cloth_list: 21 | combi *= count + 1 22 | 23 | return combi - 1 24 | -------------------------------------------------------------------------------- /study-2nd/level2/jihye/Solution1.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String solution(String s) { 3 | // answer: Jaden Case로 바꾼 문자열 4 | String answer = ""; 5 | 6 | for (int i = 0; i < s.length(); i++) { 7 | // 문자열의 맨 첫번째 문자이거나 바로 앞이 공백인 문자인 경우 8 | if (i == 0 || s.charAt(i-1) == ' ') { 9 | answer += Character.toString(s.charAt(i)).toUpperCase(); 10 | } else { 11 | answer += Character.toString(s.charAt(i)).toLowerCase(); 12 | } 13 | } 14 | return answer; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /study-2nd/level2/yongseong/Solution01.js: -------------------------------------------------------------------------------- 1 | function solution(nums) { 2 | // 폰켓몬 배열의 중복 제거 3 | var uniq = nums.reduce(function(a, b) { 4 | if (a.indexOf(b) < 0) { 5 | a.push(b); 6 | } 7 | return a; 8 | }, []); 9 | 10 | const ponketmonTypeNumber = uniq.length; // 폰켓몬의 종류 11 | const ponketmonPickNumber = nums.length/2; // 폰켓몬을 선택할 수 있는 갯수 12 | 13 | if (ponketmonTypeNumber >= ponketmonPickNumber) { 14 | return ponketmonPickNumber; 15 | } 16 | else { 17 | return ponketmonTypeNumber; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /study-2nd/level3/jihye/Solution02.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Solution { 4 | 5 | public int solution(int n, int[][] computers) { 6 | 7 | boolean[] visited = new boolean[computers.length]; 8 | 9 | // answer: 네트워크의 개수 10 | int answer = 0; 11 | for(int i = 0, i < n; i++){ 12 | IsNetwork(i); 13 | } 14 | 15 | return answer; 16 | } 17 | 18 | // bfs() 19 | public void IsNetwork(){ 20 | Queue queue = new Queue(); 21 | 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /study-1st/team1/Hash/jihun/Solution04.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | 4 | def solution(genres, plays): 5 | answer = [] 6 | d = defaultdict(lambda: [0, []]) 7 | 8 | for i, g in enumerate(genres): 9 | d[g][0] += plays[i] 10 | d[g][1].append((plays[i], i)) 11 | 12 | for _, l in sorted(d.values(), reverse=True): 13 | songs = sorted(l, reverse=True)[:2] 14 | 15 | if len(songs) == 2 and songs[0][0] == songs[1][0]: 16 | songs[0], songs[1] = songs[1], songs[0] 17 | 18 | answer += [i for _, i in songs] 19 | 20 | return answer 21 | -------------------------------------------------------------------------------- /study-2nd/level1/yunji/Solution01.kt: -------------------------------------------------------------------------------- 1 | class Solution01 { 2 | fun solution(s: String): String { 3 | var answer = "" 4 | val wordUpper = s.toUpperCase() 5 | val wordLower = s.toLowerCase() 6 | 7 | var index = 0 8 | var lengthCount = 0 9 | while (lengthCount < s.length) { 10 | answer += if (index % 2 == 0) wordUpper[lengthCount] else wordLower[lengthCount] 11 | 12 | if (s[lengthCount] == ' ') 13 | index = -1 14 | 15 | index++ 16 | lengthCount++ 17 | } 18 | 19 | return answer 20 | } 21 | } -------------------------------------------------------------------------------- /study-2nd/level3/Solution01.java: -------------------------------------------------------------------------------- 1 | class Solution01 { 2 | int result = 0; 3 | 4 | public long solution(int n) { 5 | jump(0, n); 6 | return result % 1234567; 7 | } 8 | 9 | private void jump(int distance, int n) { 10 | if (distance == n) 11 | result++; 12 | else if (distance < n) { // 아직 끝까지 가지 않았다면 13 | jump(distance + 1, n); // 현재 위치에서 1칸 점프 14 | jump(distance + 2, n); // 현재 위치에서 2칸 점프 15 | } 16 | } 17 | 18 | public static void main(String[] args) { 19 | System.out.println(new Solution01().solution(3)); 20 | } 21 | } -------------------------------------------------------------------------------- /study-1st/team2/DFS/Hyungsuk/iron-bar.js: -------------------------------------------------------------------------------- 1 | function solution(arrangement) { 2 | let stackSize = 0; 3 | let arrLength = arrangement.length; 4 | let numStick = 0; 5 | for(let i = 0; i < arrLength; i++) { 6 | if(arrangement[i] === '(') { 7 | if(arrangement[i + 1] === ')') { 8 | // lazer 9 | numStick += stackSize; 10 | i++; 11 | } else { 12 | stackSize++; 13 | } 14 | } else { 15 | stackSize--; 16 | numStick++; 17 | } 18 | } 19 | 20 | return numStick; 21 | } 22 | -------------------------------------------------------------------------------- /study-2nd/level2/yongseong/Solution02.js: -------------------------------------------------------------------------------- 1 | function solution(n) { 2 | const naturalNumber = n; 3 | const originalBinaryNumber = naturalNumber.toString(2); 4 | const originalNumberOfOne = originalBinaryNumber.match(/1/g).length; 5 | 6 | // n++ 인 반복문 7 | while (n < 1000000) { 8 | // 증가된 n을 2진수로 변환 9 | n++; 10 | var binaryNumber = n.toString(2); 11 | var numberOfOne = binaryNumber.match(/1/g).length; 12 | 13 | // 원래 n과 증가된 n의 2진수의 1의 갯수를 비교해서 맞으면 n을 return 14 | if (originalNumberOfOne == numberOfOne) { 15 | return n; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /study-1st/team2/Stack/Shinje/IronBar.java: -------------------------------------------------------------------------------- 1 | import java.util.Stack; 2 | 3 | class IronBar { 4 | public int solution(String arrangement) { 5 | int answer = 0; 6 | arrangement = arrangement.replace("()", "C"); 7 | String[] arr = arrangement.split(""); 8 | Stack stack = new Stack(); 9 | 10 | for (int i = 0; i < arr.length; i++) { 11 | if (arr[i].equals("(")) { 12 | stack.push("("); 13 | } else if (arr[i].equals(")")) { 14 | stack.pop(); 15 | answer += 1; 16 | } else { 17 | answer += stack.size(); 18 | } 19 | } 20 | 21 | return answer; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /study-2nd/level3/jihye/Solution01.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Solution { 4 | public long solution(int n, int[] works) { 5 | int lastIndex = works.length-1; 6 | 7 | while(n > 0){ 8 | Arrays.sort(works); 9 | 10 | // 배열 works의 모든 원소가 0일때 11 | if(works[lastIndex] == 0){ 12 | break; 13 | } 14 | 15 | works[lastIndex]--; 16 | n--; 17 | } 18 | 19 | long answer = 0; 20 | for( int work : works ){ 21 | answer += work * work; 22 | } 23 | return answer; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /study-2nd/level3/seungju/solution01.js: -------------------------------------------------------------------------------- 1 | function solution(aList, bList) { 2 | 3 | // TODO: - Optimize for time performance 4 | const teamBScore = aList.reduce((sum, a) => { 5 | // -1 if index is not found 6 | const BThatWins = bList.filter((b) => b > a); 7 | const smallestBThatWins = Math.min(...BThatWins); 8 | const smallestBThatWinsIndex = bList.indexOf(smallestBThatWins); 9 | 10 | 11 | if (smallestBThatWinsIndex >= 0) { 12 | bList.splice(smallestBThatWinsIndex, 1); 13 | return sum + 1; 14 | } else { 15 | return sum; 16 | } 17 | }, 0) 18 | 19 | return teamBScore; 20 | } -------------------------------------------------------------------------------- /study-1st/team2/DFS/jihye/Solution01.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int answer = 0; 3 | 4 | public int solution(int[] numbers, int target) { 5 | depthFirstSearch(numbers, target, 1, numbers[0]); 6 | depthFirstSearch(numbers, target, 1, (-1) * numbers[0]); 7 | return answer; 8 | } 9 | 10 | public void depthFirstSearch(int[] numbers, int target, int depth, int sum){ 11 | if(depth >= numbers.length){ 12 | if(sum==target) 13 | answer++; 14 | return; 15 | } 16 | depthFirstSearch(numbers,target, depth+1 , sum + numbers[depth]); 17 | depthFirstSearch(numbers,target, depth+1 , sum - numbers[depth]); 18 | } 19 | } -------------------------------------------------------------------------------- /study-2nd/level2/yunji/Solution02.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Solution02 { 4 | public static boolean solution(String[] phoneBook) { 5 | List phoneNums = new ArrayList<>(Arrays.asList(phoneBook)); 6 | Collections.sort(phoneNums, Comparator.comparingInt(String::length)); 7 | 8 | for (int i = 0; i < phoneNums.size(); i++) { 9 | for (int j = i + 1; j < phoneNums.size(); j++) { 10 | String num = phoneNums.get(i); 11 | if (phoneNums.get(j).substring(0, num.length()).equals(num)) { 12 | return false; 13 | } 14 | } 15 | } 16 | 17 | return true; 18 | } 19 | } -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/Shinje/PrimeNumber.java: -------------------------------------------------------------------------------- 1 | public class PrimeNumber { 2 | public int solution(String numbers) { 3 | int answer = 0; 4 | return answer; 5 | } 6 | 7 | public int[] getNumberArr(String numbers) { 8 | // 순열을 이용해서 가능한 모든 경우의 수를 만듦 9 | // 순열 부분이 어려워서 코드를 보며 이해하는 중입니다 10 | int[] result = null; 11 | 12 | return result; 13 | } 14 | 15 | public int getPrimeNumberCount(int num) { 16 | int count = 0; 17 | for (int i = 2; i <= num; i++) { 18 | for (int j = 1; j <= Math.sqrt(i); j++) { 19 | if ((j != 1) & (i % j == 0)) { 20 | break; 21 | } else if (j + 1 > Math.sqrt(i)) { 22 | count++; 23 | } 24 | } 25 | } 26 | 27 | return count; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /study-1st/team1/Search/byeongguk/Solution01.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | def solution(answers): 5 | order = [] 6 | points = [0, 0, 0] 7 | patterns = [ 8 | [1, 2, 3, 4, 5], 9 | [2, 1, 2, 3, 2, 4, 2, 5], 10 | [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] 11 | ] 12 | 13 | for index, answer in enumerate(answers): 14 | if answer == patterns[0][index % 5]: points[0] += 1 15 | if answer == patterns[1][index % 8]: points[1] += 1 16 | if answer == patterns[2][index % 10]: points[2] += 1 17 | 18 | for index, point in enumerate(points, 1): 19 | if point == max(points): 20 | order.append(index) 21 | 22 | return order 23 | -------------------------------------------------------------------------------- /study-1st/team2/Stack/sangeun/Top.java: -------------------------------------------------------------------------------- 1 | public class Top { 2 | public static int[] solution(int[] heights) { 3 | int[] answer = new int[heights.length]; 4 | 5 | for (int i = heights.length - 1 ; i > 0 ; i--) { 6 | for (int j = i - 1 ; j >= 0 ; j--) { 7 | if (heights[i] < heights[j]) { 8 | answer[i] = j + 1; 9 | break; 10 | } 11 | } 12 | } 13 | return answer; 14 | } 15 | 16 | public static void main(String[] args) { 17 | int[] heights = {3,9,9,3,5,7,2}; 18 | int[] result = solution(heights); 19 | for (int i = 0 ; i < result.length ; i++) { 20 | System.out.print(result[i] + " "); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /study-1st/team2/Stack/juhyun/Solution01.java: -------------------------------------------------------------------------------- 1 | class Solution01{ 2 | public int solution(String arrangement) { 3 | int answer = 0; 4 | 5 | Stack stack = new Stack<>(); 6 | 7 | for(int i =0; i= m){ 8 | big = n; 9 | small = m; 10 | }else{ 11 | big = m; 12 | small = n; 13 | } 14 | 15 | while(true){ 16 | quotient = big/small; 17 | remainder = big - (quotient * small); 18 | if(remainder == 0){ 19 | gcm = small; 20 | lcm = (n*m) / gcm; 21 | break; 22 | } 23 | big = small; 24 | small = remainder; 25 | } 26 | answer = new int[] {gcm, lcm}; 27 | return answer; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/sangeun/Carpet.java: -------------------------------------------------------------------------------- 1 | public class Carpet { 2 | public static int[] solution(int brown, int red) { 3 | int T = (int)Math.ceil(Math.sqrt(brown + red)); 4 | 5 | for (int i = T; ; i++) { 6 | for (int j = T; j >= 0 ; j--) { 7 | if (i * j == brown + red && 2 * (i + j) - 4 == brown) { 8 | int[] answer = {i, j}; 9 | return answer; 10 | } 11 | } 12 | } 13 | 14 | 15 | 16 | } 17 | public static void main(String[] args) { 18 | int brown = 10; 19 | int red = 2; 20 | int[] result = solution(brown, red); 21 | 22 | for (int i = 0 ; i < result.length ; i++) { 23 | System.out.print(result[i]); 24 | } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /study-2nd/level2/seungjin/solution01.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] solution(int brown, int red) { 3 | int[] answer = new int[2]; 4 | 5 | int x=0; 6 | int y=0; 7 | 8 | //x, y 9 | int add = (brown+4)/2; 10 | int mul = brown + red; 11 | 12 | for(int i=0; i<=add; i++){ 13 | x = i; 14 | y = (add-i); 15 | 16 | if(x*y == mul){ 17 | break; 18 | } 19 | } 20 | 21 | if(x 1: 5 | for i in range(2, num//2 + 1): 6 | if (num/i) == (num//i): 7 | return False 8 | else: 9 | return True 10 | else: 11 | return False 12 | 13 | def solution(numbers): 14 | p = list() 15 | s = list() 16 | count = 0 17 | for i in range(len(numbers)): 18 | n = list(permutations(list(numbers), i+1)) 19 | p.extend(n) 20 | for i in range(len(p)): 21 | s.append("".join(p[i])) 22 | s = list(set(list(map(int, s)))) 23 | for num in s: 24 | if primen(num): 25 | count += 1 26 | return count 27 | 28 | numbers = "17" 29 | print(solution(numbers)) -------------------------------------------------------------------------------- /study-1st/team1/Search/dongkun/search-3.py: -------------------------------------------------------------------------------- 1 | def solution(baseball): 2 | possible = [] 3 | allcase = [case for case in range(123,988) if len(set(list(str(case)))) == 3 and not('0' in str(case))] 4 | for case in allcase: 5 | for game in baseball: 6 | strikeCount = strike(case, game[0]) 7 | ballCount = ball(case, game[0]) 8 | if strikeCount != game[1] or ballCount != game[2]: 9 | break 10 | else: 11 | possible.append(case) 12 | return len(possible) 13 | 14 | def strike(n1, n2): 15 | return len([c1 for c1, c2 in zip(str(n1),str(n2)) if c1 == c2 ]) 16 | 17 | def ball(n1, n2): 18 | return len([c for c in str(n1) if c in str(n2)]) - strike(n1, n2) 19 | 20 | print(solution([[123, 1, 1], [356, 1, 0], [327, 2, 0], [489, 0, 1]])) -------------------------------------------------------------------------------- /study-1st/team1/Sort/jiwon/solution1.py: -------------------------------------------------------------------------------- 1 | def solution(array, commands): 2 | start = list() 3 | last = list() 4 | pick = list() 5 | aanswer = list() 6 | answer = list() 7 | for i in range(len(commands)): 8 | start.append(commands[i][0]) 9 | last.append(commands[i][1]) 10 | pick.append(commands[i][2]) 11 | for i in range(len(start)): 12 | c = array.copy() 13 | c = array[start[i]-1:last[i]] 14 | c.sort() 15 | aanswer.append(c) 16 | for i in range(len(pick)): 17 | answer.append(aanswer[i][pick[i]-1]) 18 | return answer 19 | 20 | array = [1, 5, 2, 6, 3, 7, 4] 21 | commands = [[2, 5, 3], [4, 4, 1], [1, 7, 3]] 22 | print(solution(array, commands)) 23 | 24 | # pick : [3, 1, 3] 25 | # answer: [[2, 3, 5, 6], [6], [1, 2, 3, 4, 5, 6, 7]] -------------------------------------------------------------------------------- /study-1st/team2/DFS/juhyun/Solution01.java: -------------------------------------------------------------------------------- 1 | public class Solution01 { 2 | 3 | static int answer = 0; 4 | 5 | public int solution(int[] numbers, int target) { 6 | DFS(target, numbers, 0); 7 | return answer; 8 | } 9 | 10 | public void DFS(int target, int[] numbers, int depth) { 11 | if(depth == numbers.length) { 12 | int sum = 0; 13 | for(int i = 0; i < numbers.length; i++) { 14 | sum += numbers[i]; 15 | } 16 | if(sum == target) { 17 | answer++; 18 | } 19 | return; 20 | } 21 | else { 22 | numbers[depth] *= 1; 23 | DFS(target, numbers, depth + 1); 24 | 25 | numbers[depth] *= -1; 26 | DFS(target, numbers, depth + 1); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /study-2nd/level2/jiwon/solution2.js: -------------------------------------------------------------------------------- 1 | function solution(name) { 2 | var answer = 0; 3 | 4 | var alpha = String.fromCharCode(cuId); 5 | var base = alpha.repeat(name.length); 6 | var baseAll = base.toString().split(""); 7 | 8 | var cuId = 65; 9 | 10 | window.addEventListener('keydown', handleKeyDown, false); 11 | function handleKeyDown(e) { 12 | if (e.keyCode === 37) { 13 | //왼쪽 화살표 - 배열의 왼쪽으로 이동 14 | }else if (e.keyCode === 39) { 15 | //오른쪽 화살표 - 배열의 오른쪽으로 이동 16 | }else{ 17 | if (e.keyCode === 38) { 18 | //위쪽 화살표 19 | cuId--; 20 | } 21 | if (e.keyCode === 40) { 22 | //아래쪽 화살표 23 | cuId++; 24 | } 25 | } 26 | }; 27 | 28 | answer = baseAll.join(""); 29 | return answer; 30 | } -------------------------------------------------------------------------------- /study-1st/team1/Search/byeongguk/Solution02.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | from itertools import permutations 5 | 6 | def solution(numbers): 7 | combinations = set() 8 | for size in range(1, len(numbers) + 1): 9 | for combination in list(permutations(numbers, size)): 10 | combinations.add(int("".join(combination))) 11 | 12 | composite = set([0, 1]) 13 | maximum = max(combinations) 14 | prime_list = [False, False] + [True] * (maximum - 1) 15 | for i, is_prime in enumerate(prime_list): 16 | if not i == 0 and not i == 1: 17 | for j in range(i, maximum + 1, i): 18 | if i != j and is_prime: 19 | prime_list[j] = False 20 | if j in combinations: 21 | composite.add(j) 22 | 23 | return len(combinations - composite) 24 | -------------------------------------------------------------------------------- /study-1st/team2/Search/Hyungsuk/test-score.js: -------------------------------------------------------------------------------- 1 | function solution(answers) { 2 | let result = []; 3 | let patterns = [ 4 | [1, 2, 3, 4, 5], 5 | [2, 1, 2, 3, 2, 4, 2, 5], 6 | [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] 7 | ]; 8 | let scores = patterns.map(pattern => checkScore(answers, pattern)); 9 | let maxScore = Math.max(...scores); 10 | for(let i = 0; i < scores.length; i++) { 11 | if(maxScore === scores[i]) { 12 | result.push(i+1); 13 | } 14 | } 15 | return result; 16 | } 17 | 18 | function checkScore(answers, pattern) { 19 | let score = 0; 20 | let patternLength = pattern.length; 21 | let answersLength = answers.length; 22 | for(let i = 0; i < answersLength; i++) { 23 | if(answers[i] === pattern[i % patternLength]) { 24 | score++; 25 | } 26 | } 27 | 28 | return score; 29 | } -------------------------------------------------------------------------------- /study-1st/team2/Stack/sangeun/StockPrice.java: -------------------------------------------------------------------------------- 1 | public class StockPrice { 2 | public static int[] solution(int[] prices) { 3 | int[] answer = new int[prices.length]; 4 | boolean[] flag = new boolean[prices.length]; 5 | for (int i = 0 ; i < prices.length ; i++) { 6 | int temp = prices[i]; 7 | for (int j = 0 ; j < i ; j++) { 8 | if (!flag[j] && temp >= prices[j]) { 9 | answer[j]++; 10 | } else { 11 | if (!flag[j]) { 12 | answer[j]++; 13 | } 14 | flag[j] = true; 15 | } 16 | } 17 | } 18 | return answer; 19 | } 20 | 21 | public static void main(String[] args) { 22 | int[] prices = {1, 2, 3, 2, 3}; 23 | int[] result = solution(prices); 24 | for (int i = 0 ; i < result.length ; i++) { 25 | System.out.print(result[i]); 26 | } 27 | 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/juhyun/Solution04.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | class Solution04 { 4 | 5 | static public void main(String args[]){ 6 | 7 | int result[] = new int[2]; 8 | int brown = 24; 9 | int red = 24; 10 | 11 | result = new Solution04().solution(brown,red); 12 | 13 | System.out.println(Arrays.toString(result)); 14 | 15 | } 16 | 17 | public int[] solution(int brown, int red) { 18 | int[] answer = new int[2]; 19 | 20 | int x = 0; 21 | int y = 0; 22 | 23 | for (int i = 1; i <= red; i++) 24 | { 25 | if (red % i == 0) { 26 | x = red/i; 27 | y = i; 28 | if((2*(x+2)+2*y) == brown){ 29 | answer[0] = y+2; 30 | answer[1] = x+2; 31 | } 32 | } 33 | } 34 | return answer; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /study-1st/team2/DFS/Shinje/WordChange.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int solution(String begin, String target, String[] words) { 3 | int answer = 0; 4 | 5 | if(isTargetFound(target, words) == false)//target이 없으면 0을 반환 6 | return 0; 7 | 8 | /** 9 | *for(int i=0; i stack = new Stack(); 9 | char handing = '0'; 10 | 11 | while(arrangement.length() != i) { 12 | if(arrangement.charAt(i) == ')') { 13 | if(handing == '(') { 14 | pieces += stack.size(); 15 | handing='0'; 16 | } 17 | 18 | else if (handing == '0') { 19 | pieces +=1; 20 | stack.pop(); 21 | } 22 | 23 | else 24 | handing = arrangement.charAt(i); 25 | 26 | } 27 | 28 | 29 | else if(arrangement.charAt(i) == '(') { 30 | if(handing == '(') { 31 | stack.push((Character)handing); 32 | } 33 | 34 | 35 | handing = arrangement.charAt(i); 36 | 37 | 38 | } 39 | 40 | i++; 41 | 42 | 43 | } 44 | 45 | return pieces; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /study-1st/team1/BF/jihun/Solution02.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | 4 | def solution(numbers): 5 | num_list = list(numbers) 6 | d = {} 7 | for i in num_list: 8 | d[i] = d.get(i, 0) + 1 9 | 10 | num_list.sort(reverse=True) 11 | max_num = int("".join(num_list)) 12 | check_list = [True for _ in range(max_num + 1)] 13 | 14 | for i in range(2, int(math.sqrt(max_num)) + 1): 15 | if check_list[i]: 16 | j = i * 2 17 | while j <= max_num: 18 | check_list[j] = False 19 | j += i 20 | 21 | ans = 0 22 | for i in range(2, max_num + 1): 23 | if check_list[i] and is_num(d, i): 24 | ans += 1 25 | 26 | return ans 27 | 28 | 29 | def is_num(d, n): 30 | l = list(str(n)) 31 | d2 = {} 32 | for i in l: 33 | d2[i] = d2.get(i, 0) + 1 34 | 35 | for key in d2.keys(): 36 | if d2[key] > d.get(key, 0): 37 | return False 38 | 39 | return True 40 | 41 | -------------------------------------------------------------------------------- /study-1st/team1/Hash/byeongguk/Solution04.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # -*- coding: utf-8 -*- 3 | 4 | def solution(genres, plays): 5 | albums = {} 6 | best_album = [] 7 | 8 | # 장르별 노래 분류 저장 및 총 실행 횟수 저장 9 | for unique_id, (genre, play) in enumerate(zip(genres, plays)): 10 | if genre not in list(albums.keys()): 11 | albums[genre] = {} 12 | albums[genre]['songs'] = [] 13 | albums[genre]['plays'] = 0 14 | 15 | albums[genre]['songs'].append((unique_id, play)) 16 | albums[genre]['plays'] += play 17 | 18 | # 장르별 총 실행 횟수 기준 내림차순 정렬 19 | albums = sorted(albums.items(), 20 | key=lambda album: album[1]['plays'], reverse=True) 21 | 22 | # 장르 내 노래 실행 횟수 기준 내림차순 정렬 및 베스트 앨범에 노래 삽입 23 | for album in albums: 24 | songs = sorted(album[1]['songs'], 25 | key=lambda song: song[1], reverse=True) 26 | 27 | for song in songs[:2]: 28 | best_album.append(song[0]) 29 | 30 | return best_album 31 | -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/haeseong/카펫.java: -------------------------------------------------------------------------------- 1 | public class 카펫 { 2 | 3 | public int[] solution(int brown, int red) { 4 | int candidate = 0; 5 | for (int i = 1; i < 5000; i++) { 6 | if (doesSatisfy(i, brown, red)) { 7 | candidate = i; 8 | break; 9 | } 10 | } 11 | int theOther = getTheOther(candidate, brown); 12 | 13 | return candidate >= theOther 14 | ? new int[]{candidate, theOther} 15 | : new int[]{theOther, candidate}; 16 | } 17 | 18 | // ((brown + 4) / 2) * x - x^2 = brown + red 19 | private boolean doesSatisfy(int candidate, int brown, int red) { 20 | int left = ((brown + 4) / 2) * candidate - candidate * candidate; 21 | int right = brown + red; 22 | return left == right; 23 | } 24 | 25 | // y = ((brown + 4) / 2) - x 26 | private int getTheOther(int candidate, int brown) { 27 | return (brown + 4) / 2 - candidate; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /study-1st/team2/DFS/Hyungsuk/printer.js: -------------------------------------------------------------------------------- 1 | function solution(priorities, location) { 2 | const target = priorities[location]; 3 | let count = 0; 4 | const samePriorityIndexs = []; 5 | const length = priorities.length; 6 | for(let i = 0; i < length; i++) { 7 | if(priorities[i] > target) { 8 | count++; 9 | } else if(priorities[i] === target) { 10 | samePriorityIndexs.push(i); 11 | } 12 | } 13 | 14 | let higherLastIndex = -1; 15 | for(let i = target + 1; i <= 9; i++) { 16 | higherLastIndex = priorities.lastIndexOf(i); 17 | if(higherLastIndex !== -1) { 18 | break; 19 | } 20 | } 21 | const sameHigherLastIndex = samePriorityIndexs.find(index => index > higherLastIndex); 22 | if(sameHigherLastIndex <= location) { 23 | count += sameHigherLastIndex - location + 1; 24 | } else {`` 25 | count += samePriorityIndexs.length - sameHigherLastIndex + location + 2; 26 | } 27 | return count; 28 | } -------------------------------------------------------------------------------- /study-1st/team2/DFS/sangeun/Network.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedList; 2 | import java.util.Queue; 3 | 4 | public class Network { 5 | public static int solution(int n, int[][] computers) { 6 | int[] visited = new int[n]; 7 | int count = 1; 8 | Queue queue = new LinkedList<>(); 9 | for (int i = 0 ; i < n ; i++) { 10 | if (visited[i] == 0) { 11 | queue.add(i); 12 | visited[i] = count; 13 | 14 | 15 | while (!queue.isEmpty()) { 16 | int v = queue.poll(); 17 | for (int j = 0 ; j < n ; j++) { 18 | if (computers[v][j] == 1 && visited[j] == 0) { 19 | queue.add(j); 20 | visited[j] = count; 21 | } 22 | } 23 | } 24 | 25 | count++; 26 | } 27 | 28 | 29 | 30 | } 31 | 32 | 33 | 34 | 35 | return count; 36 | } 37 | public static void main(String[] args) { 38 | int n = 3; 39 | int[][] computers = {{1, 1, 0}, {1, 1, 1}, {0, 1, 1}}; 40 | 41 | int answer = solution(n, computers); 42 | 43 | System.out.println(answer - 1); 44 | 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/Shinje/PreTest.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | 4 | class Solution { 5 | public int[] solution(int[] answers) { 6 | int[] answer = null; 7 | int[] num_1 = { 1, 2, 3, 4, 5 }; 8 | int[] num_2 = { 2, 1, 2, 3, 2, 4, 2, 5 }; 9 | int[] num_3 = { 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 }; 10 | int count_1 = 0; 11 | int count_2 = 0; 12 | int count_3 = 0; 13 | int max_count = 0; 14 | 15 | for (int i = 0; i < answers.length; i++) { 16 | 17 | if (num_1[i%5] == answers[i]) count_1++; 18 | if (num_2[i%8] == answers[i]) count_2++; 19 | if (num_3[i%10] == answers[i]) count_3++; 20 | 21 | } 22 | 23 | max_count = Math.max(count_1, Math.max(count_2, count_3)); 24 | 25 | List list = new ArrayList<>(); 26 | if(max_count == count_1) list.add(1); 27 | if(max_count == count_2) list.add(2); 28 | if(max_count == count_3) list.add(3); 29 | 30 | answer = new int[list.size()]; 31 | for(int i=0; i linkedList = new LinkedList<>(); 7 | 8 | if (priorities.length == 1) 9 | return 1; 10 | 11 | for (int priority : priorities) 12 | linkedList.add(priority); 13 | 14 | while (true) { 15 | Integer value = linkedList.pollFirst(); 16 | if (linkedList.isEmpty()) 17 | return priorities.length; 18 | 19 | int max = Collections.max(linkedList); 20 | 21 | if (value < max) { 22 | linkedList.addLast(value); 23 | 24 | if (location == 0) 25 | location = linkedList.size(); 26 | } else { 27 | answer++; // 값이 하나 빠져나갈 때 1씩 증가 28 | 29 | if (location == 0) 30 | break; 31 | } 32 | 33 | location--; 34 | } 35 | 36 | return answer; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/yunji/Solution01.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | // 완전탐색 - 모의고사 4 | public class Solution01 { 5 | public int[] solution(int[] answers) { 6 | ArrayList result = new ArrayList<>(); 7 | int[] count = new int[3]; 8 | int[][] answerSet = { 9 | {1, 2, 3, 4, 5}, 10 | {2, 1, 2, 3, 2, 4, 2, 5}, 11 | {3, 3, 1, 1, 2, 2, 4, 4, 5, 5} 12 | }; 13 | 14 | for (int i = 0; i < answers.length; i++) { 15 | if (answers[i] == answerSet[0][i % 5]) 16 | count[0]++; 17 | 18 | if (answers[i] == answerSet[1][i % 8]) 19 | count[1]++; 20 | 21 | if (answers[i] == answerSet[2][i % 10]) 22 | count[2]++; 23 | } 24 | 25 | int max = (count[0] > count[1]) ? count[0] : count[1]; 26 | max = (max > count[2]) ? max : count[2]; 27 | 28 | for (int i = 0; i < 3; i++) { 29 | if (max == count[i]) 30 | result.add(i + 1); 31 | } 32 | 33 | return result.stream().mapToInt(i -> i).toArray(); 34 | } 35 | } -------------------------------------------------------------------------------- /study-1st/team2/Stack/yunji/Solution01.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | class Solution { 4 | public int solution(String arrangement) { 5 | ArrayList laserArray = new ArrayList<>(); 6 | int answer = 0, start = 0, index = -2; 7 | int stick = 0; // 막대기의 개수 8 | 9 | // 레이저의 위치를 구한다 10 | while (true) { 11 | int temp = arrangement.indexOf("()", start++); 12 | if (temp == -1) break; 13 | 14 | if (index != temp) { 15 | index = temp; 16 | laserArray.add(index); 17 | } 18 | } 19 | 20 | for (int i = 0, j = 0; i < arrangement.length(); i++) { 21 | if ((arrangement.charAt(i) == '(') && i != laserArray.get(j)) { 22 | stick++; // '(' 기호 등장시 절단할 막대기 추가 23 | } else if (arrangement.charAt(i) == ')') { 24 | stick--; // ')' 기호 등장시 절단할 막대기 제거 25 | answer++; 26 | } else if (i == laserArray.get(j)) { // 레이저 등장시 절단 27 | answer += stick; 28 | i++; 29 | j++; 30 | } 31 | } 32 | 33 | return answer; 34 | } 35 | } -------------------------------------------------------------------------------- /study-1st/team2/Stack/juhyun/Solution03.java: -------------------------------------------------------------------------------- 1 | import java.util.Stack; 2 | 3 | class Solution03{ 4 | public static void main(String[] args) { 5 | 6 | // int[] heights = {6,9,5,7,4}; 7 | int[] heights = {3,9,9,3,5,7,2}; 8 | 9 | for(int i = 0; i < heights.length; i++){ 10 | int[] result = new Solution03().solution(heights); 11 | System.out.println("result = " + result[i]); 12 | } 13 | } 14 | 15 | public int[] solution(int[] heights) { 16 | int[] answer = new int[heights.length]; 17 | int size = heights.length; 18 | 19 | Stack stack = new Stack<>(); 20 | 21 | for(int i = 0; i< size ; i++) 22 | stack.push(heights[i]); 23 | 24 | //answer[]에 들어가는 index 25 | int index = size-1; 26 | 27 | while(!stack.empty()) { 28 | int top = stack.pop(); 29 | 30 | for (int i = stack.size() - 1; i >= 0; i--) { 31 | if (top < heights[i]) { 32 | answer[index] = i+1; 33 | break; 34 | } 35 | } 36 | index--; 37 | } 38 | return answer; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /study-1st/team2/DFS/yunji/Solution03.java: -------------------------------------------------------------------------------- 1 | class Solution03 { 2 | boolean[] status; 3 | int answer; 4 | 5 | public int solution(String begin, String target, String[] words) { 6 | status = new boolean[words.length]; 7 | checkWord(begin, target, words, 0); 8 | 9 | return answer; 10 | } 11 | 12 | public void checkWord(String word, String target, String[] words, int answer) { 13 | if (!word.equals(target)) { 14 | for (int i = 0; i < words.length; i++) { 15 | if (checkSpell(word, words[i])) { 16 | if (!status[i]) { 17 | status[i] = true; 18 | checkWord(words[i], target, words, ++answer); 19 | } 20 | } 21 | } 22 | } else 23 | this.answer = answer; 24 | } 25 | 26 | public static boolean checkSpell(String word, String target) { 27 | int checkSpell = 0; 28 | 29 | for (int i = 0; i < word.length(); i++) { 30 | if (target.charAt(i) != word.charAt(i)) 31 | checkSpell++; 32 | 33 | if (checkSpell > 2) 34 | return false; 35 | } 36 | 37 | return (checkSpell == 1); 38 | } 39 | } -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/yunji/Solution02.java: -------------------------------------------------------------------------------- 1 | public class Solution02 { 2 | public boolean checkNumber(String numbers, int num) { 3 | int[] countList = new int[10]; 4 | int[] checkList = new int[10]; 5 | for (int i = 0; i < numbers.length(); i++) 6 | countList[numbers.charAt(i) - '0']++; 7 | 8 | while (num != 0) { 9 | if (countList[num % 10] == 0 || 10 | checkList[num % 10] >= countList[num % 10]) 11 | return false; 12 | 13 | checkList[num % 10]++; 14 | num /= 10; 15 | } 16 | 17 | return true; 18 | } 19 | 20 | public int solution(String numbers) { 21 | int answer = 0; 22 | 23 | for (int i = 2; i < Math.pow(10, numbers.length()) - 1; i++) { 24 | if (checkNumber(numbers, i)) { 25 | if (isPrime(i)) { 26 | System.out.println(i); 27 | answer++; 28 | } 29 | } 30 | } 31 | 32 | return answer; 33 | } 34 | 35 | public static boolean isPrime(int n) { 36 | if (n == 2) return true; 37 | for (int i = 2; i < n; i++) { 38 | if (n % i == 0) 39 | return false; 40 | } 41 | 42 | return true; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/sangeun/NumberBaseball.java: -------------------------------------------------------------------------------- 1 | public class NumberBaseball { 2 | public static int solution(int[][] baseball) { 3 | int answer = 0; 4 | 5 | for (int i = 100 ; i <= 999 ; i++) { 6 | String temp = String.valueOf(i); 7 | if (temp.charAt(0) == temp.charAt(1) || temp.charAt(1) == temp.charAt(2) || temp.charAt(0) == temp.charAt(2)) { 8 | continue; 9 | } 10 | if (temp.charAt(0) == '0' || temp.charAt(1) == '0' || temp.charAt(2) == '0') { 11 | continue; 12 | } 13 | boolean flag = true; 14 | for (int j = 0 ; j < baseball.length ; j++) { 15 | String A = String.valueOf(baseball[j][0]); 16 | int strike = 0; 17 | int ball = 0; 18 | for (int k = 0 ; k < 3 ; k++) { 19 | for (int l = 0 ; l < 3 ; l++) { 20 | if (k == l && temp.charAt(k) == A.charAt(l)) { 21 | strike++; 22 | } 23 | if (k != l && temp.charAt(k) == A.charAt(l)) { 24 | ball++; 25 | } 26 | } 27 | } 28 | if (strike != baseball[j][1] || ball != baseball[j][2]) { 29 | flag = false; 30 | break; 31 | } 32 | } 33 | 34 | if (flag) { 35 | answer++; 36 | } 37 | } 38 | return answer; 39 | } 40 | public static void main(String[] args) { 41 | int[][] baseball = {{123, 1, 1}, {356, 1, 0}, {327, 2, 0}, {489, 0, 1}}; 42 | System.out.println(solution(baseball)); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/sangeun/Test.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Test { 4 | public static int[] solution(int[] answers) { 5 | 6 | int[] num1 = {1, 2, 3, 4, 5}; 7 | int[] num2 = {2, 1, 2, 3, 2, 4, 2, 5}; 8 | int[] num3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; 9 | 10 | int player1 = 0; 11 | int player2 = 0; 12 | int player3 = 0; 13 | 14 | for (int i = 0 ; i < answers.length ; i++) { 15 | if (answers[i] == num1[i % 5]) { 16 | player1++; 17 | } 18 | if (answers[i] == num2[i % 8]) { 19 | player2++; 20 | } 21 | if (answers[i] == num3[i % 10]) { 22 | player3++; 23 | } 24 | } 25 | 26 | ArrayList result = new ArrayList<>(); 27 | 28 | int max = Math.max(player1, Math.max(player2, player3)); 29 | 30 | if (player1 == max) { 31 | result.add(1); 32 | } 33 | if (player2 == max) { 34 | result.add(2); 35 | } 36 | if (player3 == max) { 37 | result.add(3); 38 | } 39 | Collections.sort(result); 40 | int[] answer = new int[result.size()]; 41 | for (int i = 0; i < answer.length; i++) { 42 | answer[i] = result.get(i); 43 | } 44 | return answer; 45 | } 46 | public static void main(String[] args) { 47 | int[] answers = {1,3,2,4,2}; 48 | int[] result = solution(answers); 49 | 50 | for (int i = 0 ; i < result.length ; i++) { 51 | System.out.print(result[i] + " "); 52 | } 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /study-1st/team2/Stack/Shinje/Printer.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedList; 2 | import java.util.PriorityQueue; 3 | import java.util.Queue; 4 | 5 | class Printer { 6 | 7 | public static void main(String[] args) { 8 | int[] priorities = { 2, 1, 3, 2 }; 9 | int location = 2; 10 | System.out.println("answer = " + solution(priorities, location)); 11 | 12 | } 13 | 14 | 15 | public static int solution(int[] priorities, int location) { 16 | int answer = 0; 17 | 18 | Queue q = new LinkedList(); 19 | 20 | for(int item : priorities) { 21 | q.add(item); 22 | } 23 | 24 | while(q.size() != 0) { 25 | 26 | } 27 | 28 | return answer; 29 | 30 | 31 | 32 | 33 | // 배열의 값과 스택의 값을 비교해서 문제를 해결하려고 했으나 실패. 34 | // int answer = 0; 35 | // Queue q = new LinkedList(); 36 | // Queue ordered_q = new PriorityQueue(); 37 | // 38 | // for (int items : priorities) { 39 | // q.add(items); 40 | // ordered_q.offer(items); 41 | // } 42 | // 43 | // System.out.println("q= " + q.size()); 44 | // System.out.println("ordered_q= " + ordered_q.size()); 45 | // 46 | // return answer; 47 | } 48 | 49 | 50 | 51 | // Queue의 Max값을 구하는 메소드를 만들기 위해 시도 52 | // public int getMaxQueueElement(Queue queue) { 53 | // PriorityQueue pQueue = new PriorityQueue<>((E e1, E e2)->e1.compareTo(e2)); 54 | // pQueue.addAll(queue); 55 | // System.out.println(pQueue.peek()); 56 | // return max; 57 | // } 58 | } 59 | -------------------------------------------------------------------------------- /study-1st/team2/DFS/yunji/Solution01.java: -------------------------------------------------------------------------------- 1 | class Solution01 { 2 | int target, height, answer = 0; 3 | 4 | public int solution(int[] numbers, int target) { 5 | Node root = new Node(0); 6 | this.target = target; 7 | this.height = numbers.length; 8 | 9 | initTree(root, numbers, 0); 10 | traverseTree(root, 0, 0); 11 | 12 | return answer; 13 | } 14 | 15 | public void traverseTree(Node current, int sum, int index) { 16 | if (current != null) { 17 | sum += current.value; 18 | if (index == height && sum == target) 19 | answer++; 20 | 21 | index++; 22 | traverseTree(current.left, sum, index); 23 | traverseTree(current.right, sum, index); 24 | } 25 | } 26 | 27 | // 순회할 트리 초기화 28 | public void initTree(Node current, int[] numbers, int index) { 29 | current.left = new Node(numbers[index]); 30 | current.right = new Node(numbers[index] * -1); 31 | 32 | index++; 33 | if (index < numbers.length) { 34 | initTree(current.left, numbers, index); 35 | initTree(current.right, numbers, index); 36 | } 37 | } 38 | 39 | class Node { 40 | int value; 41 | Node left, right; 42 | 43 | public Node(int value) { 44 | this.value = value; 45 | this.left = null; 46 | this.right = null; 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/juhyun/Solution01.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Collection; 3 | import java.util.Collections; 4 | import java.util.HashMap; 5 | 6 | public class Solution01 { 7 | 8 | public int[] solution(int[] answers) { 9 | 10 | int[] a = {1, 2, 3, 4, 5}; 11 | int[] b = {2, 1, 2, 3, 2, 4, 2, 5}; 12 | int[] c = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; 13 | 14 | HashMap score = new HashMap<>(); 15 | 16 | score.put(1,0); 17 | score.put(2,0); 18 | score.put(3,0); 19 | 20 | for(int i = 0; i values = score.values(); 28 | int max = Collections.max(values); 29 | 30 | //리스트에 최댓값 넣기 31 | ArrayList scoreList = new ArrayList<>(); 32 | 33 | for(int i = 1; i<=score.size(); i++){ 34 | if(max == score.get(i)) { 35 | scoreList.add(i); 36 | } 37 | } 38 | 39 | //정답 배열 만들기 40 | int[] answer = new int[scoreList.size()]; 41 | 42 | for(int i = 0; i 0) { 30 | node = stack.pop(); 31 | if (history.indexOf(node) < 0) { 32 | history.push(node); 33 | // Push all the connected nodes into the stack 34 | graph[node].forEach((i) => stack.push(i)); 35 | } 36 | } 37 | 38 | return history; 39 | } 40 | 41 | function isUnique(value, index, self) { 42 | // Is value within the Array? 43 | return self.indexOf(value) === index; 44 | } 45 | -------------------------------------------------------------------------------- /study-1st/team2/DFS/Seungjin/Solution01.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.Arrays; 3 | import java.util.Stack; 4 | import java.lang.Math; 5 | 6 | class Solution { 7 | static int baseLog(int x, int base) {return (int)(Math.log10(x) / Math.log10(base));} 8 | static int Left(int a){return 2*a;} 9 | static int Right(int a){return 2*a+1;} 10 | static int GetLayer(int a){return baseLog(a, 2);} 11 | 12 | int solution(int [] numbers, int target) { 13 | Stack tree = new Stack(); 14 | int MAX_NUMBER = (int)(Math.pow(2, numbers.length+1)+1); 15 | System.out.println(MAX_NUMBER); 16 | int answer = 0; 17 | int [] dp = new int[MAX_NUMBER+1]; 18 | Arrays.fill(dp, 0); 19 | 20 | dp[0] = 0; 21 | dp[1] = 0; 22 | dp[2] = numbers[0]; //LEFT 23 | dp[3] = -numbers[0]; //RIGHT 24 | 25 | tree.push(2); 26 | tree.push(3); 27 | 28 | while(!tree.empty()){ 29 | int pop_index = tree.pop(); 30 | 31 | if(Right(pop_index) <= MAX_NUMBER-1){ 32 | dp[Left(pop_index)] = (dp[pop_index] + numbers[GetLayer(Left(pop_index))-1]); 33 | dp[Right(pop_index)] = (dp[pop_index] - numbers[GetLayer(Right(pop_index))-1]); 34 | tree.push(Left(pop_index)); 35 | tree.push(Right(pop_index)); 36 | } 37 | 38 | else{ 39 | if(dp[pop_index] == target){ 40 | answer++; 41 | System.out.println(answer); 42 | } 43 | } 44 | } 45 | 46 | return answer; 47 | 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /study-1st/team2/Stack/juhyun/Solution02.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class Solution02 { 4 | 5 | public static void main(String[] args) { 6 | 7 | int[] priorities1 = {2,1,3,2}; 8 | int[] priorities2 = {1,1,9,1,1,1}; 9 | 10 | int location = 0; 11 | 12 | System.out.println("result = " + new Solution02().solution(priorities2,location)); 13 | 14 | } 15 | 16 | class PrintInfo{ 17 | int priority; 18 | int index; 19 | 20 | public PrintInfo(int index, int priority){ 21 | this.index = index; 22 | this.priority = priority; 23 | } 24 | } 25 | 26 | public int solution(int[] priorities, int location) { 27 | int answer = 0; 28 | int cursur = 0; 29 | 30 | ArrayList printList = new ArrayList<>(); 31 | 32 | for(int i = 0; i queue, B1 target) { 18 | boolean result = true; 19 | Iterator iter = queue.iterator(); 20 | while (iter.hasNext()) { 21 | if (target.priority < iter.next().priority) { 22 | result = false; 23 | break; 24 | } 25 | } 26 | return result; 27 | } 28 | public static int solution(int[] priorities, int location) { 29 | Queue queue = new LinkedList<>(); 30 | 31 | // 모든 priority 값 queue에 add 32 | for (int i = 0 ; i < priorities.length ; i++) { 33 | // location 값은 true, 나머지는 false 34 | if (location == i) { 35 | queue.add(new B1(priorities[i], true)); 36 | } else { 37 | queue.add(new B1(priorities[i], false)); 38 | } 39 | } 40 | 41 | int count = 1; 42 | while (true) { 43 | if (!checkFunc(queue, queue.peek())) { 44 | // queue에 더 큰 수가 있을 경우 => 큐의 제일 뒤에 삽 45 | B1 temp = queue.poll(); 46 | queue.add(temp); 47 | } else { 48 | B1 temp = queue.poll(); 49 | if (temp.check) { 50 | // location! break 51 | break; 52 | } else { 53 | // queue에서 삭제하고 count 증 54 | count++; 55 | } 56 | } 57 | } 58 | 59 | return count; 60 | } 61 | public static void main(String[] args) { 62 | int[] priorities = {2, 1, 3, 2}; 63 | int location = 3; 64 | System.out.println(solution(priorities, location)); 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /study-2nd/level3/Solution02.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Solution02 { 4 | 5 | public int solution(int n, int[][] edge) { 6 | int answer = 0; 7 | Queue queue = new LinkedList<>(); 8 | int[] visitCount = new int[n + 1]; 9 | 10 | Graph graph = new Graph(n); 11 | for (int[] ints : edge) { // 그래프 초기화 12 | graph.put(ints[0], ints[1]); 13 | } 14 | 15 | queue.add(1); // 시작점은 1번 노드 16 | while (queue.size() > 0) { 17 | int queueVal = queue.poll(); 18 | for (Integer nearNode : graph.getNode(queueVal)) { 19 | if (visitCount[nearNode] == 0) { // 아직 방문한 적이 없다면 20 | visitCount[nearNode] = visitCount[queueVal] + 1; // 이전 노드까지의 거리에서 + 1 21 | queue.add(nearNode); // 큐에 노드 추가 22 | } 23 | } 24 | } 25 | 26 | int max = 0; 27 | for (int i = 2; i < visitCount.length; i++) { // 가장 먼 노드 개수 세기 28 | if (visitCount[i] > max) { // 더 멀리있는 노드를 찾았을 때 29 | max = visitCount[i]; 30 | answer = 1; 31 | } else if (visitCount[i] == max) { 32 | answer++; 33 | } 34 | } 35 | 36 | return answer; 37 | } 38 | 39 | class Graph { 40 | private List> graph; 41 | 42 | public Graph(int size) { 43 | this.graph = new ArrayList<>(); 44 | for (int i = 0; i < size + 1; i++) { 45 | graph.add(new ArrayList<>()); 46 | } 47 | } 48 | 49 | public List getNode(int x) { 50 | return this.graph.get(x); 51 | } 52 | 53 | public void put(int x, int y) { 54 | graph.get(x).add(y); 55 | graph.get(y).add(x); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /study-1st/team2/Stack/sangeun/FunctionDevelop.java: -------------------------------------------------------------------------------- 1 | package rithm3.algo; 2 | 3 | import java.util.*; 4 | 5 | class B3 { 6 | int progress; 7 | int speed; 8 | public B3(int progress, int speed) { 9 | // TODO Auto-generated constructor stub 10 | this.progress = progress; 11 | this.speed = speed; 12 | } 13 | } 14 | public class FunctionDevelop { 15 | public static int[] solution(int[] progresses, int[] speeds) { 16 | Queue queue = new LinkedList<>(); 17 | ArrayList result = new ArrayList<>(); 18 | // 큐에 작업 일수 추가 19 | // 작업이 몇 일 걸리는지 계산 20 | for (int i = 0 ; i < progresses.length ; i++) { 21 | queue.add((int)Math.floor(1.0 * (100 - progresses[i]) / speeds[i])); 22 | } 23 | 24 | 25 | int count = 1; 26 | int temp = queue.poll(); 27 | while (!queue.isEmpty()) { 28 | if (temp >= queue.peek()) { 29 | // queue의 처음과 같이 배포되는 작업(앞 작업보다 일찍 끝난 작업) 30 | count++; 31 | queue.poll(); 32 | } else { 33 | // 앞 작업과 같이 배포되지 않는 오래 걸리는 작업 34 | result.add(count); 35 | count = 1; 36 | temp = queue.poll(); 37 | } 38 | } 39 | 40 | // while (!queue.isEmpty()) { 41 | // int count = 1; 42 | // 43 | // int temp = queue.poll(); 44 | // while (!queue.isEmpty() && temp > queue.peek()) { 45 | // queue.poll(); 46 | // count++; 47 | // } 48 | // Arr.add(count); 49 | // } 50 | // 마지막 결과 result에 추가 51 | result.add(count); 52 | 53 | // 출력 부분 54 | int[] answer = new int[result.size()]; 55 | for (int i = 0; i < answer.length; i++) { 56 | answer[i] = result.get(i); 57 | } 58 | return answer; 59 | } 60 | 61 | public static void main(String[] args) { 62 | int[] speeds = {1, 30, 5 , 10, 60, 7}; 63 | int[] progresses = {93, 30, 55, 60, 40, 65}; 64 | int[] result = solution(progresses, speeds); 65 | for (int i = 0 ; i < result.length ; i++) { 66 | System.out.print(result[i] + " "); 67 | } 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /study-2nd/level2/seungju/solution02.js: -------------------------------------------------------------------------------- 1 | function solution(numbers) { 2 | 3 | const letters = numbers.split("") 4 | 5 | const primeNumbers = permutationOf(letters) 6 | .map((s) => parseInt(s)) 7 | .filter(isUnique) 8 | .filter(isPrimeNumber) 9 | 10 | return primeNumbers.length 11 | } 12 | 13 | function permutationOf(letters) { 14 | // The seed is provided when there is only one letter 15 | if (letters.length === 1) { 16 | return Array(letters.pop()); 17 | } 18 | 19 | // Recursive function after saving the last letter 20 | const lastLetter = letters.pop(); 21 | const permutations = permutationOf(letters); 22 | 23 | // Add the last letter to each of the permutated arrays 24 | // e.g., ["701"] + "1" -> ["1701", "7101", "7011", "7011"] 25 | const permutationsWithLetterAdded = [] 26 | permutations.forEach((permutation) => { 27 | Array(permutation.length + 1) 28 | .fill() 29 | .map((_, i) => (i)) 30 | .forEach((index) => { 31 | const t = permutation.split("") 32 | t.splice(index, 0 ,lastLetter) 33 | permutationsWithLetterAdded.push(t.join("")) 34 | }) 35 | }) 36 | 37 | permutationsWithLetterAdded.push(lastLetter); 38 | return permutations.concat(permutationsWithLetterAdded); 39 | } 40 | 41 | function isPrimeNumber(n) { 42 | // [2, ..., n - 1] 43 | const dividers = Array(n) 44 | .fill() 45 | .map((_, i) => (i)) 46 | .slice(2) 47 | // If n can be divided, it is not a prime number 48 | for (const divider of dividers) { 49 | if(n % divider === 0) { 50 | return false 51 | }; 52 | } 53 | return n > 1 54 | } 55 | 56 | function isUnique(value, index, self) { 57 | // Is value within the Array? 58 | return self.indexOf(value) === index; 59 | } -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/yunji/Solution03.java: -------------------------------------------------------------------------------- 1 | // 완전탐색 - 숫자야구 2 | public class Solution03 { 3 | public static void main(String[] args) { 4 | int[][] test = new int[][]{ 5 | {123, 1, 1}, 6 | {356, 1, 0}, 7 | {327, 2, 0}, 8 | {489, 0, 1} 9 | }; 10 | 11 | int an = new Solution03().solution(test); 12 | System.out.println(an); 13 | } 14 | 15 | public int[] splitNumber(int num) { 16 | return new int[]{num / 100, num % 100 / 10, num % 10}; 17 | } 18 | 19 | public int solution(int[][] baseball) { 20 | int answer = 0, count = 0; 21 | int s = 0, b = 0; 22 | 23 | for (int i = 123; i <= 999; i++) { 24 | for (int[] ints : baseball) { 25 | int[] numArray = splitNumber(ints[0]); // 비교할 숫자 26 | int[] candidateArray = splitNumber(i); // 후보 숫자 27 | 28 | // 스트라이크 검사 29 | for (int j = 0; j < 3; j++) { 30 | if (numArray[j] == candidateArray[j]) 31 | s++; 32 | } 33 | 34 | // 볼 검사 35 | for (int j = 0; j < 3; j++) { 36 | if (numArray[j] != candidateArray[j]) { 37 | if (j != 0 && numArray[j] == candidateArray[0]) 38 | b++; 39 | else if (j != 1 && numArray[j] == candidateArray[1]) 40 | b++; 41 | else if (j != 2 && numArray[j] == candidateArray[2]) 42 | b++; 43 | } 44 | } 45 | 46 | if (s == ints[1] && b == ints[2]) 47 | count++; 48 | 49 | s = 0; 50 | b = 0; 51 | } 52 | 53 | if (baseball.length == count) { 54 | if (!String.valueOf(i).contains("0")) 55 | answer++; 56 | } 57 | 58 | count = 0; 59 | } 60 | return answer; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /study-1st/team2/Stack/sangeun/Bridge.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class B2 { 4 | int truck_weight; 5 | int level; 6 | public B2(int truck_weight) { 7 | // TODO Auto-generated constructor stub 8 | this.truck_weight = truck_weight; 9 | this.level = 1; // 생성 후 큐에 바로 들어가기 때문에 경과 시간 1로 초기화 10 | } 11 | } 12 | public class Bridge { 13 | public static int solution(int bridge_length, int weight, int[] truck_weights) { 14 | Queue queue = new LinkedList<>(); 15 | 16 | int count = 0; // 경과 시간 17 | int current_weight = 0; // 다리의 현재 무게 18 | int next_truck = 0; // 대기중인 트럭 index 19 | boolean flag = true; // 마지막 트럭까지 다리에 진입했을 경우 flag값 false 20 | 21 | while (true) { 22 | count++; // while문이 한 번 돌면 1 time의 시간 경과 23 | if (!flag && queue.isEmpty()) { // 마지막 트럭이 빠져나왔을 경우 24 | break; // 반복문을 빠져나옴 25 | } 26 | // 현재 다리 위에 있는 트럭들의 level 증가 27 | Iterator iter = queue.iterator(); 28 | while (iter.hasNext()) { 29 | B2 temp = iter.next(); 30 | temp.level++; 31 | } 32 | // 대기중인 트럭이 있고, 다리에 여유가 있을 때 트럭 입장 33 | if (next_truck < truck_weights.length && current_weight + truck_weights[next_truck] <= weight) { 34 | current_weight += truck_weights[next_truck]; 35 | queue.add(new B2(truck_weights[next_truck++])); 36 | // 마지막 트럭일 경우 flag false로 set 37 | if (next_truck == truck_weights.length) { 38 | flag = false; 39 | } 40 | } 41 | // 트럭이 다리를 다 지나가서 빠져나갈 경우 42 | if (queue.peek().level == bridge_length) { 43 | B2 temp = queue.poll(); 44 | // poll 이후 현재 다리 무게에서 빠져나간 트럭 무게 - 45 | current_weight -= temp.truck_weight; 46 | } 47 | } 48 | return count; 49 | } 50 | 51 | public static void main(String[] args) { 52 | int[] truck_weights = {10,10,10,10,10,10,10,10,10,10}; 53 | int bridge_length = 100; 54 | int weight = 100; 55 | System.out.println(solution(bridge_length, weight, truck_weights)); 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /study-1st/team2/DFS/sangeun/Word.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedList; 2 | import java.util.Queue; 3 | 4 | public class Word { 5 | public static int compareWords(String A, String B) { 6 | int counts = 0; 7 | for (int i = 0 ; i < A.length() ; i++) { 8 | if (A.charAt(i) != B.charAt(i)) { 9 | counts++; 10 | } 11 | if (counts > 1) { 12 | return 2; 13 | } 14 | } 15 | if (counts == 0) { 16 | return 0; 17 | } else { 18 | return 1; 19 | } 20 | } 21 | 22 | public static int solution(String begin, String target, String[] words) { 23 | 24 | Queue queue = new LinkedList<>(); 25 | int[][] map = new int[words.length][words.length]; 26 | int[] visited = new int[words.length]; 27 | 28 | int count = 0; 29 | for (int i = 0 ; i < words.length ; i++) { 30 | if (compareWords(begin, words[i]) == 1) { 31 | queue.add(i); 32 | count = 1; 33 | visited[i] = count; 34 | break; 35 | } 36 | } 37 | if (count == 0) { 38 | return count; 39 | } else { 40 | for (int i = 0 ; i < words.length ; i++) { 41 | for (int j = 0 ; j < words.length ; j++) { 42 | if (i == j) { 43 | continue; 44 | } else { 45 | if (compareWords(words[i], words[j]) == 1) { 46 | map[i][j] = 1; 47 | map[j][i] = 1; 48 | } 49 | } 50 | } 51 | } 52 | 53 | // for (int i = 0 ; i < words.length ; i++) { 54 | // for (int j = 0 ; j < words.length ; j++) { 55 | // System.out.print(map[i][j] + " "); 56 | // } 57 | // System.out.println(); 58 | // } 59 | while (!queue.isEmpty()) { 60 | int v = queue.poll(); 61 | 62 | for (int i = 0 ; i < words.length ; i++) { 63 | 64 | if (map[v][i] == 1 && visited[i] == 0) { 65 | queue.add(i); 66 | visited[i] = visited[v] + 1; 67 | } 68 | } 69 | } 70 | } 71 | 72 | for (int i = 0 ; i < words.length ; i++) { 73 | if (compareWords(target, words[i]) == 0) { 74 | return visited[i]; 75 | } 76 | } 77 | return 0; 78 | } 79 | public static void main(String[] args) { 80 | String begin = "hit"; 81 | String target = "cog"; 82 | String[] words = {"hot", "dot", "dog", "lot", "log", "cog"}; 83 | 84 | System.out.println(solution(begin, target, words)); 85 | 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 취업하고싶고리즘 :computer: 2 | =========================== 3 | 4 | 디프만 6기 2차 개발 스터디인 `취업하고싶고리즘`의 저장소입니다. (1차 스터디 공지사항은 [링크](https://github.com/depromeet/algorithm-6th/tree/master/study-1st)에서 확인이 가능합니다) 5 | 6 | ### 진행 개요 7 | 8 | - 프로그래머스의 [스킬체크](https://programmers.co.kr/skill_checks) 1~3 레벨을 풉니다. 9 | - 매주 레벨 하나씩 풀어옵니다. 10 | 11 | ### 참가자 12 | 13 | 이윤지, 현지혜, 정승진, 이지원, 김승주, 전용성 14 | 15 | ### 진행 기간 16 | 17 | 5월 18일부터 3주 18 | 19 | ### 규칙 20 | 21 | - 이론 공부는 셀프입니다. 토요일에는 자신의 코드를 돌아가면서 설명합니다. 22 | - 문제는 미리 풀어서 목요일까지 업로드해야 합니다. 23 | - 짝꿍의 코드는 토요일 세션 전에 반드시 온라인 상으로 리뷰를 해야하며, 확인이 완료되면 짝꿍이 merge를 해주세요. 24 | - 꼭 코드를 지적해야만 하는게 아니라, 궁금한 것을 물어보거나 칭찬을 해주는 것도 좋습니다. 25 | - 특별한 사정이 없는데 문제풀이 또는 리뷰를 빼먹으면 5000원의 벌금이 있습니다. 문제를 풀지 못했을 때는 풀려고 시도한 흔적을 남긴다면 OK 26 | - 벌금은 액수가 적으면 기부하고, 많을 경우 우리가 먹을 간식으로 환원됩니다. 27 | 28 | ### 짝꿍 편성 29 | * 1주차 30 | 31 | ``` 32 | 지혜(Java) - 승진(Java) 33 | 윤지(Java) - 승주(JavaScript) 34 | 용성(JavaScript) - 지원(JavaScript) 35 | ``` 36 | 37 | 38 | * 3주차 39 | 40 | ``` 41 | 윤지 - 용성 42 | 지원 - 지혜 43 | 승진 - 승주 44 | ``` 45 | 46 | ### commit message 양식 47 | 48 | - commit message는 `[레벨명] {문제번호} {상태}` 양식에 맞춰 작성해주세요. 49 | - 상태에는 `풀이완료, 풀이 중, 수정` 셋 중 하나가 들어가면 됩니다. ex) `[level2] 1번, 2번 풀이완료`, `[level1] 1번 풀이 중` 50 | - 라벨을 만들어두었으니 필요에 따라 추가해주세요. 51 | 52 | ### 디렉토리 양식 53 | - 파일을 올릴 때 경로는 `study-2nd\레벨\이름\파일명` 양식으로 통일해주세요. ex) `study-2nd\level1\yunji\Solution1.java` 54 | 55 | ### 진행 현황 56 | 57 | > 진행 현황은 디프만 Slack의 #algo-study-6th 채널에서도 확인이 가능합니다. 58 | 59 | 60 | - [출석체크 및 벌금 현황](https://github.com/depromeet/algorithm-6th/blob/master/attendance.md) 61 | 62 | ### 더 많은 문제가 필요한 사람을 위한 링크 모음 63 | 64 | > 추천하고 싶은 사이트가 있으시다면 여기에 이어서 작성해주세요. 65 | 66 | - [백준 알고리즘](https://www.acmicpc.net/) 67 | - [프로그래머스](https://programmers.co.kr/) 68 | - [Codewars](https://www.codewars.com/) 69 | - [Code jam](https://code.google.com/codejam/) 70 | - [프로젝트 오일러](http://euler.synap.co.kr/prob_list.php) 71 | - [코딩도장](http://codingdojang.com/) 72 | - [Algospot](https://algospot.com/judge/problem/list/) 73 | - [Hackerrank](https://www.hackerrank.com/) 74 | - [SW Expert Academy](https://swexpertacademy.com/main/main.do) 75 | - [Codeground](https://www.codeground.org/) 76 | - [LeetCode](https://leetcode.com/) 77 | - [GeeksforGeeks](https://www.geeksforgeeks.org/) 78 | - [LintCode](https://www.lintcode.com/) 79 | 80 | ### 제보받은 링크 81 | - https://www.youtube.com/user/damazzang 82 | - https://baked-corn.tistory.com/ 83 | - http://codeforces.com/ (추천 by 요정님) 84 | -------------------------------------------------------------------------------- /study-1st/README.md: -------------------------------------------------------------------------------- 1 | 취업하고싶고리즘 :computer: 2 | =========================== 3 | 4 | 디프만 6기 1차 개발 스터디인 `취업하고싶고리즘`의 저장소입니다. 5 | 6 | ### 진행 개요 7 | 8 | - 프로그래머스의 [많이 출제되는 알고리즘 문제 그룹](https://programmers.co.kr/learn/challenges) 10개 중 3개를 풉니다. 9 | - 한주에 하나씩 풉니다. 10 | 11 | ### 참가자 12 | 13 | 이윤지, 최형석, 김신제, 현지혜, 이동건, 정승진, 김지은, 김지원, 공병국, 오유경, 최지훈, 이상은, 김주현 14 | 15 | ### 진행 기간 16 | 17 | 3월 23일부터 3주 18 | 19 | ### 조 편성 20 | 21 | | 언어 | 1팀 (Python) | 2팀 (Java) | 22 | |------|------------------------|------------------------------| 23 | | 이름 | 병국(팀장), 지원, 지훈, 동건, 유경, 지은 | 윤지(팀장), 상은, 승진, 지혜, 신제, 형석, 주현 | 24 | 25 | ### 규칙 (아직 확정 X) 26 | 27 | - 이론 공부는 셀프입니다. 28 | - 매주 문제 그룹 선택은 조별로 다수결에 따라 결정합니다. (그날 출석하지 않은 사람은 투표권이 없습니다) 29 | - 스터디 당일 날에는 리뷰를 진행하고, 문제는 집에서 미리 풀어와야합니다. 30 | - 같은 팀 사람이 PR을 넣었을 때 읽어보고 피드백이 있다면 코멘트를 달아주세요. 31 | - 특별한 사정이 없는데 빼먹으면 5000원의 벌금이 있습니다. 절반 이상 풀었거나, 풀려고 시도한 흔적을 남긴다면 OK 32 | - 벌금은 액수가 적으면 기부하고, 많을 경우 우리가 먹을 간식으로 환원됩니다. 33 | 34 | ### commit message 양식 35 | 36 | - commit message는 `[단원명] {문제이름} {상태}` 양식에 맞춰 작성해주세요. 37 | - 상태에는 `풀이완료, 풀이 중, 수정` 셋 중 하나가 들어가면 됩니다. ex) `[완전탐색] 모의고사, 소수찾기 풀이완료` 38 | - 라벨을 만들어두었으니 필요에 따라 추가해주세요. 39 | 40 | ### 디렉토리 양식 41 | - 파일을 올릴 때 경로는 `팀명\문제 그룹명\이름\파일명` 양식으로 통일해주세요. ex) `team1\Hash\yunji\Solution01.java` 42 | 43 | ### 진행 현황 44 | 45 | > 진행 현황은 디프만 Slack의 #algo-study-6th 채널에서도 확인이 가능합니다. 46 | - 출석체크 및 벌금 현황 : [1팀](https://github.com/depromeet/algorithm-6th/blob/master/team1-status.md), [2팀](https://github.com/depromeet/algorithm-6th/blob/master/team2-status.md) 47 | - 1주 차 48 | - 1팀 : 해시 49 | - 2팀 : DFS/BFS 50 | - 2주 차 51 | - 1팀 : 정렬 52 | - 2팀 : 스택/큐 53 | - 3주 차 54 | - 1팀 : 완전탐색 55 | - 2팀 : 완전탐색 56 | 57 | ### 더 많은 문제가 필요한 사람을 위한 링크 모음 58 | 59 | > 추천하고 싶은 사이트가 있으시다면 여기에 이어서 작성해주세요. 60 | 61 | - [백준 알고리즘](https://www.acmicpc.net/) 62 | - [프로그래머스](https://programmers.co.kr/) 63 | - [Codewars](https://www.codewars.com/) 64 | - [Code jam](https://code.google.com/codejam/) 65 | - [프로젝트 오일러](http://euler.synap.co.kr/prob_list.php) 66 | - [코딩도장](http://codingdojang.com/) 67 | - [Algospot](https://algospot.com/judge/problem/list/) 68 | - [Hackerrank](https://www.hackerrank.com/) 69 | - [SW Expert Academy](https://swexpertacademy.com/main/main.do) 70 | - [Codeground](https://www.codeground.org/) 71 | - [LeetCode](https://leetcode.com/) 72 | - [GeeksforGeeks](https://www.geeksforgeeks.org/) 73 | - [LintCode](https://www.lintcode.com/) 74 | 75 | ### 제보받은 링크 76 | - https://www.youtube.com/user/damazzang 77 | - https://baked-corn.tistory.com/ 78 | - http://codeforces.com/ (추천 by 요정님) 79 | -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/haeseong/모의고사.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Arrays; 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | import java.util.stream.IntStream; 6 | 7 | public class 모의고사 { 8 | 9 | public int[] solution(int[] answers) { 10 | List answerList = IntStream.of(answers) 11 | .boxed() 12 | .collect(Collectors.toList()); 13 | 14 | int firstScore = Student.FIRST.solve(answerList); 15 | int secondScore = Student.SECOND.solve(answerList); 16 | int thirdScore = Student.THIRD.solve(answerList); 17 | 18 | int maxScore = Math.max(firstScore, Math.max(secondScore, thirdScore)); 19 | 20 | List results = new ArrayList<>(); 21 | if (firstScore == maxScore) { 22 | results.add(Student.FIRST.getNumber()); 23 | } 24 | if (secondScore == maxScore) { 25 | results.add(Student.SECOND.getNumber()); 26 | } 27 | if (thirdScore == maxScore) { 28 | results.add(Student.THIRD.getNumber()); 29 | } 30 | return results.stream() 31 | .mapToInt(i -> i) 32 | .toArray(); 33 | } 34 | 35 | 36 | public enum Student { 37 | FIRST(1, Pattern.of(1, 2, 3, 4, 5)), 38 | SECOND(2, Pattern.of(2, 1, 2, 3, 2, 4, 2, 5)), 39 | THIRD(3, Pattern.of(3, 3, 1, 1, 2, 2, 4, 4, 5, 5)); 40 | 41 | private Integer number; 42 | private Pattern pattern; 43 | 44 | Student(Integer number, Pattern pattern) { 45 | this.number = number; 46 | this.pattern = pattern; 47 | } 48 | 49 | public Integer getNumber() { 50 | return number; 51 | } 52 | 53 | public int solve(List problems) { 54 | return (int) problems.stream() 55 | .filter(problem -> pattern.getAnswer().equals(problem)) 56 | .count(); 57 | } 58 | } 59 | 60 | public static class Pattern { 61 | private final List answers; 62 | private final int size; 63 | private int current; 64 | 65 | private Pattern(List answers, int size, int current) { 66 | this.answers = answers; 67 | this.size = size; 68 | this.current = current; 69 | } 70 | 71 | public static Pattern of(int... numbers) { 72 | List answers = IntStream.of(numbers) 73 | .boxed() 74 | .collect(Collectors.toList()); 75 | return new Pattern(answers, answers.size(), 0); 76 | } 77 | 78 | public Integer getAnswer() { 79 | Integer answer = answers.get(current); 80 | current = (current + 1) % size; 81 | return answer; 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /study-2nd/level2/seungjin/page_rank.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import operator 3 | from collections import defaultdict 4 | nesteddict = defaultdict(dict) 5 | 6 | 7 | out_val = {} 8 | in_val = {} 9 | in_link = defaultdict(dict) 10 | pr_val = {} 11 | d_pr_val = {} 12 | 13 | count = 1002 14 | d = 0.99 15 | 16 | 17 | #nesteddict['abc']['spam'] = 'ham' 18 | graph = defaultdict(dict) 19 | 20 | #Reading 21 | with open("data.csv",'r',) as csv_file: 22 | reader = csv.reader(csv_file) 23 | for row in reader: 24 | try: 25 | in_val[row[1]] +=1 26 | except KeyError: 27 | in_val[row[1]] = 1 28 | 29 | try: 30 | out_val[row[0]] +=1 31 | except KeyError: 32 | out_val[row[0]] = 1 33 | 34 | try: 35 | in_link[row[1]][row[0]] += 1 36 | except KeyError: 37 | in_link[row[1]][row[0]] = 1 38 | 39 | pr_val[row[0]] = 0 40 | pr_val[row[1]] = 0 41 | 42 | 43 | for i in pr_val: 44 | pr_val[i] = 1/count 45 | 46 | 47 | 48 | #print(in_link) 49 | 50 | print(1/count) 51 | 52 | # First 53 | for link in in_link: 54 | ip = link 55 | d_pr_val[ip] = (1-d)/count 56 | for connect_ip in in_link[ip]: #add link with node 57 | d_pr_val[ip] += (pr_val[connect_ip]/out_val[connect_ip])*d*in_link[ip][connect_ip] 58 | for ip in d_pr_val: 59 | pr_val[ip] = d_pr_val[ip] 60 | 61 | 62 | 63 | #iterate 64 | # Second ~ 65 | for i in range(0,500): 66 | for link in in_link: 67 | ip = link 68 | d_pr_val[ip] = (1-d)/count 69 | for connect_ip in in_link[ip]: 70 | d_pr_val[ip] += (pr_val[connect_ip]/out_val[connect_ip])*d*in_link[ip][connect_ip] 71 | for ip in d_pr_val: 72 | pr_val[ip] = d_pr_val[ip] 73 | 74 | 75 | 76 | """ 77 | # Second ~ 78 | for link in in_link: 79 | ip = link 80 | for connect_ip in in_link[ip]: 81 | try : 82 | pr_val[ip] +=(pr_val[connect_ip] / out_val[connect_ip])*in_link[ip][connect_ip] 83 | except KeyError: 84 | pr_val[connect_ip] = initial_val/out_val[connect_ip] 85 | pr_val[ip] +=(pr_val[connect_ip] / out_val[connect_ip])*in_link[ip][connect_ip] 86 | 87 | 88 | # First ~ 89 | for i in range(0,1000): 90 | for link in in_link: 91 | ip = link 92 | d_pr_val[ip] = (1-d)*initial_val 93 | for connect_ip in in_link[ip]: 94 | try : 95 | d_pr_val[ip] += (pr_val[connect_ip]/out_val[connect_ip])*d*in_link[ip][connect_ip] 96 | except KeyError: 97 | pr_val[connect_ip] = 0 98 | d_pr_val[ip] += (pr_val[connect_ip]/out_val[connect_ip])*d*in_link[ip][connect_ip] 99 | 100 | for ip in d_pr_val: 101 | pr_val[ip] = d_pr_val[ip] 102 | """ 103 | 104 | 105 | 106 | sorted = sorted(pr_val.items(), key=operator.itemgetter(1), reverse=True) 107 | 108 | for i in range(0,30): 109 | #print("IP :" + i + " value : " + pr_val[i]) 110 | print(sorted[i]) 111 | 112 | -------------------------------------------------------------------------------- /study-1st/team2/DFS/Seungjin/Solution03.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.Arrays; 3 | import java.util.LinkedList; 4 | import java.lang.Math; 5 | import java.util.Queue; 6 | 7 | class index_log { 8 | int index; 9 | long log; 10 | int count; 11 | 12 | public index_log(int index, long log, int count){ 13 | this.index = index; 14 | this.log = log; 15 | this.count = count; 16 | } 17 | 18 | } 19 | 20 | class Solution { 21 | static long DropTheBit(int b){int a = 1; b++; return (a << (b-1));} 22 | 23 | public int solution(String begin, String target, String[] words){ 24 | // public static void main(String[] args){ 25 | // String begin = "hit"; 26 | // String target = "cog"; 27 | // String words[] = {"hot","dot","dog","lot","log","cog"}; 28 | 29 | 30 | int MAX = 9999999; 31 | 32 | int min = MAX; 33 | int can_change_number = begin.length()-1; 34 | long [] ok_next_flag = new long[words.length]; // ok_flag & index = 1 --> next_ok 35 | long ok_target_flag = 0; // ok_flag & index - 1 --> ok 36 | long ok_begin_flag = 0; 37 | int target_index = -1; 38 | Arrays.fill(ok_next_flag,0); 39 | 40 | for(int i = 0; i< words.length; i++){ 41 | 42 | for(int j=i; j tree = new LinkedList(); 88 | for(int i=0; i 0 && i != target_index && target_index != -1) 90 | tree.add(new index_log(i,DropTheBit(i),1)); //Index, Log, count 91 | 92 | 93 | while(!tree.isEmpty()){ 94 | index_log now = tree.poll(); 95 | 96 | //if((ok_target_flag & DropTheBit(now.index)) > 0){ 97 | //if((ok_next_flag[target_index] & DropTheBit(now.index)) > 0) { 98 | if(now.index == target_index){ 99 | min = min > now.count ? now.count : min; 100 | break; 101 | } 102 | 103 | 104 | for(int i=0; i 0){ 106 | if((now.log & DropTheBit(i))>0); 107 | else tree.add(new index_log(i,now.log | DropTheBit(i), now.count+1)); 108 | } 109 | } 110 | } 111 | 112 | if(min == MAX) 113 | min = 0; 114 | 115 | 116 | //System.out.println(min); 117 | return min; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /study-1st/team2/BruteForce/haeseong/소수_찾기.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.HashSet; 3 | import java.util.List; 4 | import java.util.Set; 5 | 6 | public class 소수_찾기 { 7 | 8 | public int solution(String numbers) { 9 | PrimeDiscriminator discriminator = PrimeDiscriminator.from(10000000); 10 | return (int) createAllNumbers(numbers) 11 | .stream() 12 | .filter(discriminator::isPrime) 13 | .count(); 14 | } 15 | 16 | private Set createAllNumbers(String number) { 17 | PermutationCalculator calculator = new PermutationCalculator(); 18 | 19 | char[] characters = number.toCharArray(); 20 | Set numberSet = new HashSet<>(); 21 | 22 | for (int i = 0; i < (2 << characters.length - 1); i++) { 23 | StringBuilder stringBuilder = new StringBuilder(); 24 | for (int j = 0; j < characters.length; j++) { 25 | if (((1 << j) & i) == 0) { 26 | continue; 27 | } 28 | stringBuilder.append(characters[j]); 29 | } 30 | String candidate = stringBuilder.toString(); 31 | if (candidate.length() == 0) { 32 | continue; 33 | } 34 | 35 | // permutation 36 | calculator.calculate(candidate.length(), candidate.toCharArray()) 37 | .stream() 38 | .map(String::valueOf) 39 | .map(Integer::valueOf) 40 | .forEach(numberSet::add); 41 | } 42 | return numberSet; 43 | } 44 | 45 | /** 46 | * https://www.baeldung.com/java-array-permutations 47 | */ 48 | public static class PermutationCalculator { 49 | 50 | public List calculate(int length, char[] elements) { 51 | List results = new ArrayList<>(); 52 | addAllCandidates(length, elements, results); 53 | return results; 54 | } 55 | 56 | private void addAllCandidates(int n, char[] elements, List results) { 57 | int[] indexes = new int[n]; 58 | for (int i = 0; i < n; i++) { 59 | indexes[i] = 0; 60 | } 61 | 62 | add(elements, results); 63 | 64 | int i = 0; 65 | while (i < n) { 66 | if (indexes[i] < i) { 67 | swap(elements, i % 2 == 0 ? 0 : indexes[i], i); 68 | add(elements, results); 69 | indexes[i] += 1; 70 | i = 0; 71 | } else { 72 | indexes[i] = 0; 73 | i += 1; 74 | } 75 | } 76 | } 77 | 78 | private void swap(char[] input, int a, int b) { 79 | char tmp = input[a]; 80 | input[a] = input[b]; 81 | input[b] = tmp; 82 | } 83 | 84 | private void add(char[] chars, List results) { 85 | char[] cloned = chars.clone(); 86 | results.add(cloned); 87 | } 88 | } 89 | 90 | /** 91 | * '에라토스테네스의 체' 방식의 소수판별기 92 | */ 93 | public static class PrimeDiscriminator { 94 | private static final int IS_PRIME_NUMBER = 0; 95 | private static final int IS_NOT_PRIME_NUMBER = 1; 96 | 97 | private final int size; 98 | private final int[] sheets; 99 | 100 | private PrimeDiscriminator(int size, int[] sheets) { 101 | this.size = size; 102 | this.sheets = sheets; 103 | initialize(); 104 | } 105 | 106 | public static PrimeDiscriminator from(int size) { 107 | return new PrimeDiscriminator(size, new int[size]); 108 | } 109 | 110 | private void initialize() { 111 | int limit = (int) Math.sqrt(size) + 1; 112 | for (int i = 2; i < limit; i++) { 113 | for (int j = 2; i * j < size; j++) { 114 | sheets[i * j] = IS_NOT_PRIME_NUMBER; 115 | } 116 | } 117 | } 118 | 119 | public boolean isPrime(int number) { 120 | if (number <= 1) { 121 | return false; 122 | } 123 | if (number >= size) { 124 | throw new IllegalArgumentException("'number' must be less than size(" + size + ")."); 125 | } 126 | return sheets[number] == IS_PRIME_NUMBER; 127 | } 128 | } 129 | } 130 | --------------------------------------------------------------------------------