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/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; + 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, "예상 출력과 다릅니다."); + } +} 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/honux/60057-Solution.java b/200204/honux/60057-Solution.java new file mode 100644 index 0000000..aec7a94 --- /dev/null +++ b/200204/honux/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; + } +} + 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, "원하는 요일명과 일치하지 않습니다."); + } +} diff --git a/README.md b/README.md index 4ab9099..28972ad 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,25 @@ # algorithm-practice -2019 코드스쿼드 백엔드 알고리즘 연습 저장소 + +2020 코드스쿼드 백엔드 알고리즘 연습 저장소 + +## 커밋하기 + +- 이 저장소를 포크한다. +- 문제를 풀고 커밋한다. 단 아래의 폴더구조를 따라 문제풀이를 작성한다. + +날짜/GitHubId/문제풀이.확장자 + +예) 20200203/honux77/Runner.java + +- 주석 등을 이용해 문제의 출처를 기입할 것 + +## 푸시 및 풀리퀘 + +- 충돌이 나지 않고 병합이 가능할 것 +- 폴더 구조 규칙을 지킬 것 +- 위 사항을 만족하면 풀리퀘는 리뷰 없이 머지된다. + +## 통계보기 + +- 주기적으로 통계를 통해 자신의 커밋수를 확인하고 열심히 풀어보자 +