From 0b3343bf387e5172875aa3557544abcf5f8b0e82 Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Mon, 3 Feb 2020 16:42:30 +0900 Subject: [PATCH 1/7] Update Readme: add commit rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 규칙내용 추가 --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 4ab9099..0d1c94c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,25 @@ # algorithm-practice + 2019 코드스쿼드 백엔드 알고리즘 연습 저장소 + +## 커밋하기 + +- 이 저장소를 포크한다. +- 문제를 풀고 커밋한다. 단 아래의 폴더구조를 따라 문제풀이를 작성한다. + +날짜/GitHubId/문제풀이.확장자 + +예) 20200203/honux77/Runner.java + +- 주석 등을 이용해 문제의 출처를 기입할 것 + +## 푸시 및 풀리퀘 + +- 충돌이 나지 않고 병합이 가능할 것 +- 폴더 구조 규칙을 지킬 것 +- 위 사항을 만족하면 풀리퀘는 리뷰 없이 머지된다. + +## 통계보기 + +- 주기적으로 통계를 통해 자신의 커밋수를 확인하고 열심히 풀어보자 + From f518e8371e4f4aac8771a5a8ee6cea62ab9bfe4b Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Mon, 3 Feb 2020 16:44:16 +0900 Subject: [PATCH 2/7] [sql] programmers sql lv.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 가장 최신 날짜 구하기 문제 --- 200203/honux77/59415.sql | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 200203/honux77/59415.sql diff --git a/200203/honux77/59415.sql b/200203/honux77/59415.sql new file mode 100644 index 0000000..943d93d --- /dev/null +++ b/200203/honux77/59415.sql @@ -0,0 +1,6 @@ +-- 가장 최근에 동물이 들어온 날짜를 좋아하는 SQL 문 +SELECT DATETIME FROM ANIMAL_INS ORDER BY DATETIME DESC LIMIT 1; + +-- 다른 풀이 +SELECT MAX(DATETIME) FROM ANIMAL_INS; + From 3dc5984f6b009d6415ac2908f4da0fb51e17dd6f Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Mon, 3 Feb 2020 16:46:34 +0900 Subject: [PATCH 3/7] Change year to 2020 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d1c94c..28972ad 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # algorithm-practice -2019 코드스쿼드 백엔드 알고리즘 연습 저장소 +2020 코드스쿼드 백엔드 알고리즘 연습 저장소 ## 커밋하기 From 4d5c8b941a0dd4001896f415715220732a514113 Mon Sep 17 00:00:00 2001 From: IdionKim Date: Tue, 4 Feb 2020 13:44:35 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A4=20=EC=B2=B4=EC=9C=A1=EB=B3=B5=20=ED=92=80?= =?UTF-8?q?=EC=9D=B4=20(#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 200203/ksundong/Solution.java | 34 +++++++++++++++++ 200203/ksundong/SolutionTest.java | 63 +++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 200203/ksundong/Solution.java create mode 100644 200203/ksundong/SolutionTest.java diff --git a/200203/ksundong/Solution.java b/200203/ksundong/Solution.java new file mode 100644 index 0000000..666f901 --- /dev/null +++ b/200203/ksundong/Solution.java @@ -0,0 +1,34 @@ +/** + * 프로그래머스 - 체육복(https://programmers.co.kr/learn/courses/30/lessons/42862) + * 1. 일단 Test Case를 만들었다. + * 2. 일단 배열의 length값을 빼고 더해보았다. (test 1, 3 실패) + * 3. 만들어 둔 Test Case를 모두 만족하는 코드를 작성하였다. + * 4. 예외 상황이 있어서(조건을 제대로 안읽어서) 코드를 수정했다. (먼저 같은 경우를 비교) + */ +public class Solution { + // 전체 학생의 수 n, 도난당한 학생의 배열 lost, 여벌의 체육복을 가진 학생의 배열 reserve + public int solution(int n, int[] lost, int[] reserve) { + n -= lost.length; + for (int i = 0; i < lost.length; i++) { + for (int j = 0; j < reserve.length; j++) { + if (lost[i] == reserve[j]) { + n++; + lost[i] = 32; + reserve[j] = -1; + break; + } + } + } + for (int i = 0; i < lost.length; i++) { + for (int j = 0; j < reserve.length; j++) { + if (lost[i] == reserve[j] + 1 || lost[i] == reserve[j] - 1) { + n++; + lost[i] = 32; + reserve[j] = -1; + break; + } + } + } + return n; + } +} diff --git a/200203/ksundong/SolutionTest.java b/200203/ksundong/SolutionTest.java new file mode 100644 index 0000000..b98fde9 --- /dev/null +++ b/200203/ksundong/SolutionTest.java @@ -0,0 +1,63 @@ +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class SolutionTest { + Solution solution; + + @BeforeEach + void setUp() { + solution = new Solution(); + } + + @Test + void testSolution1() { + int n = 5; + int[] lost = {2, 4}; + int[] reserve = {1, 3, 5}; + int expected = 5; + int actual = solution.solution(n, lost, reserve); + assertEquals(expected, actual, "예상 출력과 다릅니다."); + } + + @Test + void testSolution2() { + int n = 5; + int[] lost = {2, 4}; + int[] reserve = {3}; + int expected = 4; + int actual = solution.solution(n, lost, reserve); + assertEquals(expected, actual, "예상 출력과 다릅니다."); + } + + @Test + void testSolution3() { + int n = 3; + int[] lost = {3}; + int[] reserve = {1}; + int expected = 2; + int actual = solution.solution(n, lost, reserve); + assertEquals(expected, actual, "예상 출력과 다릅니다."); + } + + @Test + void testSolution4() { + int n = 5; + int[] lost = {4, 5}; + int[] reserve = {4}; + int expected = 4; + int actual = solution.solution(n, lost, reserve); + assertEquals(expected, actual, "예상 출력과 다릅니다."); + } + + @Test + void testSolution5() { + int n = 10; + int[] lost = {3, 9, 10}; + int[] reserve = {3, 8, 9}; + int expected = 9; + int actual = solution.solution(n, lost, reserve); + assertEquals(expected, actual, "예상 출력과 다릅니다."); + } +} From 5353120ed89f934d7b540c3530aab3e19d3a463d Mon Sep 17 00:00:00 2001 From: IdionKim Date: Tue, 4 Feb 2020 18:33:27 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A4=202016=EB=85=84=20=ED=92=80=EC=9D=B4=20(#87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 200204/ksundong/Solution.java | 20 ++++++++++++++++++++ 200204/ksundong/SolutionTest.java | 31 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 200204/ksundong/Solution.java create mode 100644 200204/ksundong/SolutionTest.java diff --git a/200204/ksundong/Solution.java b/200204/ksundong/Solution.java new file mode 100644 index 0000000..8bf6345 --- /dev/null +++ b/200204/ksundong/Solution.java @@ -0,0 +1,20 @@ +/* + * 프로그래머스 2016년 - https://programmers.co.kr/learn/courses/30/lessons/12901 + * - Test Case를 하나 만들었다. + * - 너무 쉬웠다. 역시 CodeSquad Java Playground! + * - https://www.inflearn.com/course/java-codesquad/dashboard + */ +public class Solution { + public String solution(int a, int b) { + String[] dayOfWeek = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; + int dateCount = 5; + int[] monthDayArray = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + for (int i = 0; i < a - 1; i++) { + dateCount += monthDayArray[i]; + } + dateCount += b - 1; + + return dayOfWeek[dateCount % 7]; + } +} diff --git a/200204/ksundong/SolutionTest.java b/200204/ksundong/SolutionTest.java new file mode 100644 index 0000000..b929549 --- /dev/null +++ b/200204/ksundong/SolutionTest.java @@ -0,0 +1,31 @@ +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class SolutionTest { + Solution solution; + + @BeforeEach + void setUp() { + solution = new Solution(); + } + + @Test + void testSolution1() { + int month = 5; + int date = 24; + String expected = "TUE"; + String actual = solution.solution(month, date); + assertEquals(expected, actual, "원하는 요일명과 일치하지 않습니다."); + } + + @Test + void testSolution2() { + int month = 1; + int date = 1; + String expected = "FRI"; + String actual = solution.solution(month, date); + assertEquals(expected, actual, "원하는 요일명과 일치하지 않습니다."); + } +} From 1764764e35cf1c3e73596b1f40d97b391a6eb6bb Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Tue, 4 Feb 2020 18:34:21 +0900 Subject: [PATCH 6/7] Honux (#88) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [honux] programmers h-index 난이도 3점 문제가 좀 이상하다. 분류는 정렬 * Add 190530 problem BOJ 달팽이 * [소니] 프로그래머스 모의고사 알고리즘 풀이 (#45) * 190524 H_index 알고리즘 풀이 * 프로그래머스 알고리즘 모의고사 문제풀이 * Wangmin 190530 문제풀이 (#57) * [Wangmin] 190523 알고리즘 가장 큰 수 풀이 * [wangmin] programmers 42747 H-index -sort * [wangmin] programmers 42840 모의고사 * [wangmin] baek joon 1913 달팽이 * Su (#46) * Add 190521 problem 프로그래머스 k번째수 * k번째 수 * h번째 인덱스 * mockExam algorithm * feat: H index, 모의고사 풀이 (#47) * [ingleby]190527 algorithm (#48) * [190527] H 알고리즘 문제풀이 제출합니다. (#49) * H-Index 문제풀이 * H-Index 문제풀이 * 모의고사 문제풀이 * [mukeunzi] 190528 모의고사 알고리즘 문제풀이 (#50) * [ruby] 모의고사 보냅니다. (#52) * programmers runner * programmers runner * k번째 수 문제풀이 -map 사용해서 slice 로 answer 에 push * refactor : map 중복제거 * h-index solution * ruby 모의고사 문제풀이 * ruby 모의고사 풀이 * Nailer Solve programmers supoja problem (#53) * Solve programmers supoja problem https://programmers.co.kr/learn/courses/30/lessons/42840 * Solve snail problem 백준 달팽이 알고리즘 문제 해결 * [Jake] 190530 달팽이 알고리즘 문제풀이 (#54) * feat: 19년 5월 21일 PS 솔루션 업데이트 프로그래머스 - K번째 수 * fix: 솔루션 파일 이동 * feat: 19년 5월 22일 PS 솔루션 업데이트 프로그래머스 - 가장 큰 수 * feat: 19년 5월 24일 PS 솔루션 업데이트 프로그래머스 - H-index * fix: H-Index 수정 나머지 논문의 포함 범위를 수정(인용 횟수가 h번 미만) * feat: 19년 5월 27일 PS 솔루션 업데이트 프로그래머스 - 모의고사 * feat: 19년 5월 30일 PS 솔루션 업데이트 백준 - 달팽이 * 프로그래머스 - 모의고사 문제 풀이 (#56) * BOJ 1913 snail (#60) * 달팽이 (#62) * Honux (#63) * BOJ 1913 snail * Update 190611 problem * [sony] algorithm, programmers findPrimeNumber (#65) - 프로그래머스 소수 찾기 문제 풀이 * feat: 19년 6월 12일 PS 솔루션 업데이트 (#67) 프로그래머스 - 소수 찾기(Level2, 완전탐색) * [Programmers - 42839] 소수 찾기 문제 풀이 (#66) * Honux (#68) * BOJ 1913 snail * Update 190611 problem * Update problem 109613 BOJ O(n) sort * feat: 19년 6월 13일 PS 솔루션 업데이트 (#69) 백준 - 수 정렬하기 3(counting sort) * 수 정렬하기3 (#70) * [Sony] BOJ algorithm 10989 (#71) - Counting sort * Honux (#72) * Fail to solve find prime 프로그래머스 문제 풀다 실패 순열로 구했는데 조합이었다. 내일 하자. * Solve programmers find prime 복잡하다... 여튼 풀긴 풀었네. * Add problem 문제 추가 * [H] 소수찾기 문제풀이 제출합니다. (#73) * H-Index 문제풀이 * H-Index 문제풀이 * 소수 찾기 문제풀이 * [wangmin] 수 정렬하기 3 (#74) * Honux (#75) * Fail to solve find prime 프로그래머스 문제 풀다 실패 순열로 구했는데 조합이었다. 내일 하자. * Solve programmers find prime 복잡하다... 여튼 풀긴 풀었네. * Add problem 문제 추가 * [H] 소수찾기 문제풀이 제출합니다. (#73) * H-Index 문제풀이 * H-Index 문제풀이 * 소수 찾기 문제풀이 * [wangmin] 수 정렬하기 3 (#74) * Add 190618 problem * Jake 문제 추가 (#77) * Fail to solve find prime 프로그래머스 문제 풀다 실패 순열로 구했는데 조합이었다. 내일 하자. * Solve programmers find prime 복잡하다... 여튼 풀긴 풀었네. * Add problem 문제 추가 * [H] 소수찾기 문제풀이 제출합니다. (#73) * H-Index 문제풀이 * H-Index 문제풀이 * 소수 찾기 문제풀이 * [wangmin] 수 정렬하기 3 (#74) * Add 190618 problem * Fail to solve 190613 algorithm * Add problems Jake 블로그 관련 문제 추가 * Try to solve BOJ 2580 Sudoku 시간이 많이 걸려서 작성 중 커밋 아직 돌아가지 않는다. * 20024 알고리즘 - 프로그래머스 문자열 압축 - 분류: 완전탐색 - 난이도: 2 - 풀만한데 시간이 좀 걸림 - 더 좋은 방법을 찾아 보자 Co-authored-by: Kong Son Park Co-authored-by: Minjae Lee <0201.mj.lee@gmail.com> Co-authored-by: jeongyongsu5366 <38351131+jeongyongsu5366@users.noreply.github.com> Co-authored-by: jack <47104203+jeuk817@users.noreply.github.com> Co-authored-by: gminiy Co-authored-by: SangYun Ha Co-authored-by: EUNJI NA Co-authored-by: Ruby Lee <48516485+ruby413@users.noreply.github.com> Co-authored-by: SeongHeum CHOI Co-authored-by: Jake Co-authored-by: JangHyoSeok --- .gitignore | 3 ++ 190624/2580-sudoku.cpp | 54 ++++++++++++++++++++++++++++++++++++ 190624/input.txt | 9 ++++++ 200204/60057-Solution.java | 56 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 190624/2580-sudoku.cpp create mode 100644 190624/input.txt create mode 100644 200204/60057-Solution.java diff --git a/.gitignore b/.gitignore index ad46b30..500f3f6 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,6 @@ typings/ # next.js build output .next + +# for cpp +a.out diff --git a/190624/2580-sudoku.cpp b/190624/2580-sudoku.cpp new file mode 100644 index 0000000..3e575f0 --- /dev/null +++ b/190624/2580-sudoku.cpp @@ -0,0 +1,54 @@ +#include +#include + +int b[9][9]; + +using namespace std; + +vector findNums(int i,int j) { + //map nums; + //checkv(i, nums); + //checkh(j, nums); + //checkbox(i,j, nums); +} + +bool find = false; + +void fillNums(int i, int j) { + if (find) return; + if (i == 9 && j == 9 && b[i][j] != 0) { + find = true; + return; + } + + int jn = j < 9 ? j + 1: j; + int in = jn == j && i < 9; i + 1: i; + + if (b[i][j] == 0) { + vector nums = findNums(i,j); + if (nums.size() == 0) return; + for (auto n: nums) { + board[i][j] = n; + fillNums(in, jn); + } + } + return; +} + +int main() { + char c; + for (int i = 0; i < 9; i++) { + for (int j = 0; j < 9; j++) { + cin >> c; + b[i][j] = c - '0'; + } + } + fillNums(0,0); + for (int i = 0; i < 9; i++) { + for (int j = 0; j < 9; j++) { + cout << b[i][j] << " "; + } + cout << "\n"; + } + return 0; +} diff --git a/190624/input.txt b/190624/input.txt new file mode 100644 index 0000000..2ea6910 --- /dev/null +++ b/190624/input.txt @@ -0,0 +1,9 @@ +0 3 5 4 6 9 2 7 8 +7 8 2 1 0 5 6 0 9 +0 6 0 2 7 8 1 3 5 +3 2 1 0 4 6 8 9 7 +8 0 4 9 1 3 5 0 6 +5 9 6 8 2 0 4 1 3 +9 1 7 6 5 2 0 8 0 +6 0 3 7 0 1 9 5 2 +2 5 8 3 9 4 7 6 0 diff --git a/200204/60057-Solution.java b/200204/60057-Solution.java new file mode 100644 index 0000000..aec7a94 --- /dev/null +++ b/200204/60057-Solution.java @@ -0,0 +1,56 @@ +//programmers 60057 카카오 공채 문자열 압축 +//어렵진 않은데 시간이 오래 걸렸다. + +import java.util.List; +import java.util.ArrayList; + +class Solution { + + private List cutString(String origin, int size) { + List ret = new ArrayList<>(); + for (int i = 0; i < origin.length(); i += size) { + int e = (i + size) > origin.length() ? origin.length(): i + size; + String str = origin.substring(i, e); + ret.add(str); + } + return ret; + } + + private String findCompressString(String str, int size) { + List slist = cutString(str, size); + + int count = 0; + StringBuffer newStr = new StringBuffer(); + + String prev = slist.get(0); + newStr.append(prev); + int repeat = 1; + for (int i = 1; i < slist.size(); i++) { + String curr = slist.get(i); + if(curr.equals(prev)) { + repeat++; + } else { + if (repeat != 1) { + newStr.append(Integer.toString(repeat)); + repeat = 1; + } + newStr.append(curr); + prev = curr; + } + } + + if (repeat != 1) { + newStr.append(Integer.toString(repeat)); + } + return newStr.toString(); + } + + public int solution(String s) { + int ans = s.length(); + for(int i = 1; i < s.length(); i++) { + ans = Math.min(ans, findCompressString(s, i).length()); + } + return ans; + } +} + From 0d2c629047a2a1e6dca420c618a4d1584af12cbd Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Tue, 4 Feb 2020 18:52:09 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[programmers-sql]=20=EC=97=AD=EC=88=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 진짜 쉬운 SQL 문제 풀이 --- 200204/honux/59035.sql | 2 ++ 200204/{ => honux}/60057-Solution.java | 0 2 files changed, 2 insertions(+) create mode 100644 200204/honux/59035.sql rename 200204/{ => honux}/60057-Solution.java (100%) diff --git a/200204/honux/59035.sql b/200204/honux/59035.sql new file mode 100644 index 0000000..ec5e6a7 --- /dev/null +++ b/200204/honux/59035.sql @@ -0,0 +1,2 @@ +-- 역순 정렬 +SELECT NAME, DATETIME FROM ANIMAL_INS ORDER BY ANIMAL_ID DESC; diff --git a/200204/60057-Solution.java b/200204/honux/60057-Solution.java similarity index 100% rename from 200204/60057-Solution.java rename to 200204/honux/60057-Solution.java