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

[이지민] - 모음사전, 카펫, 반지, 몬스터 트럭, 필터 #3

Merged
merged 6 commits into from
Sep 18, 2022

Conversation

jeeminimini
Copy link
Member

@jeeminimini jeeminimini commented Sep 11, 2022

📌 from issue #1 📌

📋문제 목록📋

모음사전 : ✅
카펫 : ✅
반지 : ✅
몬스터 트럭 : ✅
필터 : ✅

📝메모

  • NubmerFormat 에러

    • 문자를 숫자로 변경 시도하다가 에러가 발생하는 경우.
    • trim()을 이용해 불필요한 공백(문장 앞뒤의 공백)을 없애줄 수 있음.
  • array에 특정 값이 포함되어있는 개수 구하기

    배열.count { it.contains(찾고자 하는 값) }
  • IntArray 출력하기

    배열.contentToString()

@jeeminimini jeeminimini changed the title [이지민] - 카펫, 반지, 몬스터 트럭, 필터 [이지민] - 모음사전, 카펫, 반지, 몬스터 트럭, 필터 Sep 17, 2022
Comment on lines +21 to +44
fun order(word: String): Int {
val list = arrayListOf("A", "E", "I", "O", "U", "")
var total = mutableSetOf<String>()

for (x1 in list) {
for (x2 in list) {
for (x3 in list) {
for (x4 in list) {
for (x5 in list) {
for (x6 in list) {
val newWord = x1 + x2 + x3 + x4 + x5 + x6
total.add(newWord)
}
}
}
}
}
}
val sortedTotal = total.filter { it.length < 6 }.sorted()
//println(sortedTotal)

return sortedTotal.indexOf(word)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드가 엄청 직관적이라서 이해하기가 좋은 것 같아요!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빈 칸까지 쳐서 for문으로 문자열 만들면 모든 경우를 구할 수 있다는 걸 생각 못했는데 이렇게 하면 되는구나 했어요!

val parking = arrayListOf<ArrayList<String>>()
for (i in 0 until x) {
parking.add(
readLine()!!.split("").drop(1).dropLast(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readLine()!! 대신 readln() 을 사용하면 좋을 것 같아요
요기 한번 보셔도 좋을 것 같습니다

fourParking.clear()
continue
}
when (fourParking.count { it.contains("X") }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고차 함수 잘 활용하신 것 같아요!!

val num = readLine()?.toInt()
var rings = arrayListOf<String>()
var sum = 0
for (i in 0 until num!!) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전 num 변수처럼 다음 입력의 개수를 표시하는 친구는 repeat(readln().toInt()) {} 이렇게 사용해요!!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num의 non-null처리를 19라인에서 ?: 연산자로 하면 !!를 안 쓸 수 있을 것 같아요!

Comment on lines +28 to +31
for (i in 1..sqrt(yellow.toDouble()).toInt()) {
if (yellow % i == 0) {
if (brown == (i + 2) * 2 + (yellow / i) * 2) {
return intArrayOf(i + 2, yellow / i + 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍👍

Comment on lines +20 to +23
val pixel = arrayListOf<ArrayList<Int>>()
for (i in 0 until x) {
pixel.add(readLine()!!.trim().split(" ").map { it.toInt() }
as ArrayList<Int>)
Copy link
Member

@soopeach soopeach Sep 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pixel을 arrayListOf<MutableList<Int>>()로 사용하시면 22번째에서 입력받은 값(readLine()!! ~~)을 별도로 as ArrayList로 캐스팅하는 대신, toMutableList()로 간단히 형변환을 해줄 수 있어요!!

@soopeach soopeach merged commit be96e1d into main Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants