Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4주차] 크레인 인형 뽑기, 의상 / [5주차] 체육복, 오픈채팅방 / [6주차] 성격유형검사, 2개 이하로 다른비트 #3

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/workspace.xml

This file was deleted.

38 changes: 38 additions & 0 deletions Lv.1/week3_Lv1.kt
Original file line number Diff line number Diff line change
@@ -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("해당 순위가 존재하지 않습니다.")
}
}
}
35 changes: 35 additions & 0 deletions Lv.1/week4_Lv1.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Solution {
fun solution(board: Array<IntArray>, moves: IntArray): Int {

var answer = 0
val basket = mutableListOf<Int>() // 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
}
}
24 changes: 24 additions & 0 deletions Lv.1/week5_Lv1.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
28 changes: 28 additions & 0 deletions Lv.1/week6_Lv1.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution {
fun solution(survey: Array<String>, 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<Char, Int>()

// 초기 매핑
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
}
}
Binary file added Lv.1/로또_최고순위_최저순위_solve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lv.1/성격유형검사하기_solve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lv.1/체육복_solve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lv.1/추억점수_solve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lv.1/크레인_인형뽑기_게임_solve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lv.2/2개이하로다른비트_solve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions Lv.2/week3_Lv2.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
}
24 changes: 24 additions & 0 deletions Lv.2/week4_Lv2.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
fun solution(clothes: Array<Array<String>>): Int {
val counts = countClothesByType(clothes)
val answer = calculateAnswer(counts)
return answer
}

fun countClothesByType(clothes: Array<Array<String>>): Map<String, Int> {
val counts = mutableMapOf<String, Int>()
for (cloth in clothes) {
val type = cloth.last()
counts[type] = counts.getOrDefault(type, 0) + 1
}
return counts
}

fun calculateAnswer(counts: Map<String, Int>): Int {
var answer = 1
for (count in counts.values) {
answer *= (count+1)
}
return answer-1
}
}
35 changes: 35 additions & 0 deletions Lv.2/week5_Lv2.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Solution {
fun solution(record: Array<String>): Array<String> {
val userInfo = mutableMapOf<String, String>() // 유저 아이디와 닉네임을 저장할 맵
val result = mutableListOf<String>() // 결과 메시지를 저장할 리스트

// 유저 아이디와 닉네임 맵 만들기
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()
}
}
Empty file added Lv.2/week6_Lv2.kt
Empty file.
Binary file added Lv.2/예상대진표_solve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lv.2/오픈채팅방_solve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lv.2/의상_solve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Lv.2/타겟넘버_solve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions minjae-son/Lv.1/week1.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// 추억 점수

class Solution {
fun solution(name:Array<String>)
}