diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index a9342bc..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Lv.1/week3_Lv1.kt b/Lv.1/week3_Lv1.kt new file mode 100644 index 0000000..6aa19c0 --- /dev/null +++ b/Lv.1/week3_Lv1.kt @@ -0,0 +1,38 @@ +// 로또 최고순위 , 최저순위 + +class Solution { + fun solution(lottos: IntArray, win_nums: IntArray): IntArray { + lateinit var answer: IntArray + var count = 0 // 0의 개수 + var correctnum = 0 // 현재 맞은 번호의 개수 + + for (lotto in lottos) { + if (lotto == 0) + count++ + else if (lotto in win_nums) + correctnum++ + } + + val maxcorrect = correctnum + count + val mincorrect = correctnum + + val maxprize = getPrize(maxcorrect) + val minprize = getPrize(mincorrect) + + answer = intArrayOf(maxprize, minprize) + return answer + } + + fun getPrize(corrects: Int) : Int { + return when (corrects) { + 6 -> 1 + 5 -> 2 + 4 -> 3 + 3 -> 4 + 2 -> 5 + 1 -> 6 + 0 -> 6 + else -> throw IllegalArgumentException("해당 순위가 존재하지 않습니다.") + } + } +} \ No newline at end of file diff --git a/Lv.1/week4_Lv1.kt b/Lv.1/week4_Lv1.kt new file mode 100644 index 0000000..ed7d1a7 --- /dev/null +++ b/Lv.1/week4_Lv1.kt @@ -0,0 +1,35 @@ +class Solution { + fun solution(board: Array, moves: IntArray): Int { + + var answer = 0 + val basket = mutableListOf() // board에서 옮겨온 원소들을 저장할 바구니 + + // 바구니에 번호 넣기 + for (move in moves) { + val lineNum = move - 1 // 이동할 열의 인덱스 계산 + var doll: Int? = null // 뽑은 인형 번호를 저장할 변수 + + // 해당 열에서 가장 위에 있는 인형 뽑기 + for (i in board.indices) { + val currentDoll = board[i][lineNum] // 해당 열의 현재 인형 + if (currentDoll != 0) { // 인형이 있는 경우 + doll = currentDoll // 해당 인형 뽑기 + board[i][lineNum] = 0 // 해당 자리는 뽑았으므로 0으로 초기화 + break + } + } + + // 바구니에 인형 넣기 + if (doll != null) { // 인형을 뽑은 경우에만 추가 + if (basket.isNotEmpty() && basket.last() == doll) { // 바구니의 마지막 인형과 같은 경우 + basket.removeAt(basket.size - 1) // 바구니에서 마지막 인형 제거 + answer += 2 // 제거된 인형은 2개이므로 정답에 추가 + } else { + basket.add(doll) // 바구니에 인형 추가 + } + } + } + + return answer + } +} \ No newline at end of file diff --git a/Lv.1/week5_Lv1.kt b/Lv.1/week5_Lv1.kt new file mode 100644 index 0000000..58bce97 --- /dev/null +++ b/Lv.1/week5_Lv1.kt @@ -0,0 +1,24 @@ +class Solution { + fun solution(n: Int, lost: IntArray, reserve: IntArray): Int { + val lostSet = lost.toSet() + val reserveSet = reserve.toSet() + + // 체육복을 도난당한 학생 중 여벌 체육복이 있는 학생 찾기 + var realLost = (lostSet - reserveSet).toList().sorted() + var realReserve = (reserveSet - lostSet).toList().sorted() + + // 바로 앞이나 뒷 사람에게 체육복 빌리기 + realLost.forEach { student -> + if (student > 1 && student - 1 in realReserve) { + realReserve -= (student - 1) + realLost -= student + } else if (student < n && student + 1 in realReserve) { + realReserve -= (student + 1) + realLost -= student + } + } + + val answer = n - realLost.size + return answer + } +} \ No newline at end of file diff --git a/Lv.1/week6_Lv1.kt b/Lv.1/week6_Lv1.kt new file mode 100644 index 0000000..0a59f16 --- /dev/null +++ b/Lv.1/week6_Lv1.kt @@ -0,0 +1,28 @@ +class Solution { + fun solution(survey: Array, choices: IntArray): String { + var answer: String = "" + val type = charArrayOf('R','T','C','F','J','M','A','N') + val score = intArrayOf(0,0,0,0,0,0,0,0) + val personality = mutableMapOf() + + // 초기 매핑 + for (i in type.indices) { + personality[type[i]] = score[i] + } + + // 각 성격 유형의 점수 부여 + for(i in survey.indices) { + personality[survey[i][1]] = personality[survey[i][1]]!! + (choices[i]-4) + } + + // 성격 유형 점수 비교 + for(i in type.indices step 2) { + if (personality[type[i]]!! >= personality[type[i + 1]]!!) { + answer += type[i] + } else { + answer += type[i + 1] + } + } + return answer + } +} \ No newline at end of file diff --git "a/Lv.1/\353\241\234\353\230\220_\354\265\234\352\263\240\354\210\234\354\234\204_\354\265\234\354\240\200\354\210\234\354\234\204_solve.png" "b/Lv.1/\353\241\234\353\230\220_\354\265\234\352\263\240\354\210\234\354\234\204_\354\265\234\354\240\200\354\210\234\354\234\204_solve.png" new file mode 100644 index 0000000..3b28630 Binary files /dev/null and "b/Lv.1/\353\241\234\353\230\220_\354\265\234\352\263\240\354\210\234\354\234\204_\354\265\234\354\240\200\354\210\234\354\234\204_solve.png" differ diff --git "a/Lv.1/\354\204\261\352\262\251\354\234\240\355\230\225\352\262\200\354\202\254\355\225\230\352\270\260_solve.png" "b/Lv.1/\354\204\261\352\262\251\354\234\240\355\230\225\352\262\200\354\202\254\355\225\230\352\270\260_solve.png" new file mode 100644 index 0000000..905663a Binary files /dev/null and "b/Lv.1/\354\204\261\352\262\251\354\234\240\355\230\225\352\262\200\354\202\254\355\225\230\352\270\260_solve.png" differ diff --git "a/Lv.1/\354\262\264\354\234\241\353\263\265_solve.png" "b/Lv.1/\354\262\264\354\234\241\353\263\265_solve.png" new file mode 100644 index 0000000..059a629 Binary files /dev/null and "b/Lv.1/\354\262\264\354\234\241\353\263\265_solve.png" differ diff --git "a/Lv.1/\354\266\224\354\226\265\354\240\220\354\210\230_solve.png" "b/Lv.1/\354\266\224\354\226\265\354\240\220\354\210\230_solve.png" new file mode 100644 index 0000000..ce0dff7 Binary files /dev/null and "b/Lv.1/\354\266\224\354\226\265\354\240\220\354\210\230_solve.png" differ diff --git "a/Lv.1/\355\201\254\353\240\210\354\235\270_\354\235\270\355\230\225\353\275\221\352\270\260_\352\262\214\354\236\204_solve.png" "b/Lv.1/\355\201\254\353\240\210\354\235\270_\354\235\270\355\230\225\353\275\221\352\270\260_\352\262\214\354\236\204_solve.png" new file mode 100644 index 0000000..881ef6b Binary files /dev/null and "b/Lv.1/\355\201\254\353\240\210\354\235\270_\354\235\270\355\230\225\353\275\221\352\270\260_\352\262\214\354\236\204_solve.png" differ diff --git "a/Lv.2/2\352\260\234\354\235\264\355\225\230\353\241\234\353\213\244\353\245\270\353\271\204\355\212\270_solve.png" "b/Lv.2/2\352\260\234\354\235\264\355\225\230\353\241\234\353\213\244\353\245\270\353\271\204\355\212\270_solve.png" new file mode 100644 index 0000000..7396cb7 Binary files /dev/null and "b/Lv.2/2\352\260\234\354\235\264\355\225\230\353\241\234\353\213\244\353\245\270\353\271\204\355\212\270_solve.png" differ diff --git a/Lv.2/week3_Lv2.kt b/Lv.2/week3_Lv2.kt new file mode 100644 index 0000000..85b64aa --- /dev/null +++ b/Lv.2/week3_Lv2.kt @@ -0,0 +1,19 @@ +// 타겟 넘버 (깊이 우선 탐색 이용) + +class Solution { + + fun solution(numbers: IntArray, target: Int): Int { + return dfs(numbers, target, 0, 0) + } + + fun dfs(numbers: IntArray, target: Int, index: Int, sum: Int): Int { // 깊이 우선 탐색 + if (index == numbers.size) { // 리프 노드 도착 시 최종 결과값 검사 + return if (sum == target) 1 else 0 + } else { + val num = numbers[index] + val add = dfs(numbers, target, index + 1, sum + num) // 다음 원소를 더하는 경우 + val subtract = dfs(numbers, target, index + 1, sum - num) // 다음 원소를 빼는 경우 + return add + subtract + } + } +} \ No newline at end of file diff --git a/Lv.2/week4_Lv2.kt b/Lv.2/week4_Lv2.kt new file mode 100644 index 0000000..7cb7034 --- /dev/null +++ b/Lv.2/week4_Lv2.kt @@ -0,0 +1,24 @@ +class Solution { + fun solution(clothes: Array>): Int { + val counts = countClothesByType(clothes) + val answer = calculateAnswer(counts) + return answer + } + + fun countClothesByType(clothes: Array>): Map { + val counts = mutableMapOf() + for (cloth in clothes) { + val type = cloth.last() + counts[type] = counts.getOrDefault(type, 0) + 1 + } + return counts + } + + fun calculateAnswer(counts: Map): Int { + var answer = 1 + for (count in counts.values) { + answer *= (count+1) + } + return answer-1 + } +} \ No newline at end of file diff --git a/Lv.2/week5_Lv2.kt b/Lv.2/week5_Lv2.kt new file mode 100644 index 0000000..f136033 --- /dev/null +++ b/Lv.2/week5_Lv2.kt @@ -0,0 +1,35 @@ +class Solution { + fun solution(record: Array): Array { + val userInfo = mutableMapOf() // 유저 아이디와 닉네임을 저장할 맵 + val result = mutableListOf() // 결과 메시지를 저장할 리스트 + + // 유저 아이디와 닉네임 맵 만들기 + for (r in record) { + val parts = r.split(" ") + if (parts.size < 2) continue // 최소한 두 개의 요소를 포함하지 않으면 건너뛴다 + val action = parts[0] + val userId = parts[1] + val nickname = if (action == "Leave") "" else parts[2] + when (action) { + "Enter", "Change" -> userInfo[userId] = nickname + } + } + + // 결과 생성 + for (r in record) { + val parts = r.split(" ") + if (parts.size < 2) continue // 최소한 두 개의 요소를 포함하지 않으면 건너뛴다 + val action = parts[0] + val userId = parts[1] + val message = when (action) { + "Enter" -> "${userInfo[userId]}님이 들어왔습니다." + "Leave" -> "${userInfo[userId]}님이 나갔습니다." + else -> continue + } + result.add(message) + } + + // 결과 배열로 변환하여 반환 + return result.toTypedArray() + } +} \ No newline at end of file diff --git a/Lv.2/week6_Lv2.kt b/Lv.2/week6_Lv2.kt new file mode 100644 index 0000000..e69de29 diff --git "a/Lv.2/\354\230\210\354\203\201\353\214\200\354\247\204\355\221\234_solve.png" "b/Lv.2/\354\230\210\354\203\201\353\214\200\354\247\204\355\221\234_solve.png" new file mode 100644 index 0000000..4f31620 Binary files /dev/null and "b/Lv.2/\354\230\210\354\203\201\353\214\200\354\247\204\355\221\234_solve.png" differ diff --git "a/Lv.2/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251_solve.png" "b/Lv.2/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251_solve.png" new file mode 100644 index 0000000..96aa42a Binary files /dev/null and "b/Lv.2/\354\230\244\355\224\210\354\261\204\355\214\205\353\260\251_solve.png" differ diff --git "a/Lv.2/\354\235\230\354\203\201_solve.png" "b/Lv.2/\354\235\230\354\203\201_solve.png" new file mode 100644 index 0000000..a8dac3a Binary files /dev/null and "b/Lv.2/\354\235\230\354\203\201_solve.png" differ diff --git "a/Lv.2/\355\203\200\352\262\237\353\204\230\353\262\204_solve.png" "b/Lv.2/\355\203\200\352\262\237\353\204\230\353\262\204_solve.png" new file mode 100644 index 0000000..94a98bd Binary files /dev/null and "b/Lv.2/\355\203\200\352\262\237\353\204\230\353\262\204_solve.png" differ diff --git a/minjae-son/Lv.1/week1.kt b/minjae-son/Lv.1/week1.kt new file mode 100644 index 0000000..c208494 --- /dev/null +++ b/minjae-son/Lv.1/week1.kt @@ -0,0 +1,5 @@ +// 추억 점수 + +class Solution { + fun solution(name:Array) +} \ No newline at end of file