전체 글
-
[백준] 3052번 : 나머지 - 코틀린(kotlin)알고리즘/백준 2022. 10. 26. 00:01
https://www.acmicpc.net/problem/3052 3052번: 나머지 각 수를 42로 나눈 나머지는 39, 40, 41, 0, 1, 2, 40, 41, 0, 1이다. 서로 다른 값은 6개가 있다. www.acmicpc.net 문제 해석 10개의 수가 주어지고 42로 나눈 서로 다른 나머지의 개수를 구하는 문제입니다. 집합을 이용해서 나머지의 값을 넣어주고 집합의 크기를 출력하면 될 것 같습니다. 코드 fun main() { val divideNumberSet = mutableSetOf() while (true) { val input = readLine() ?: break if (input.isEmpty() || input.isEmpty()) { break } val curNumber = ..
-
[백준] 9498 : 시험 성적 - 코틀린(Kotlin)알고리즘/백준 2022. 10. 25. 00:01
https://www.acmicpc.net/problem/9498 9498번: 시험 성적 시험 점수를 입력받아 90 ~ 100점은 A, 80 ~ 89점은 B, 70 ~ 79점은 C, 60 ~ 69점은 D, 나머지 점수는 F를 출력하는 프로그램을 작성하시오. www.acmicpc.net 문제 해석 다른 언어라면 if-else를 활용하겠지만 코틀린에는 when을 활용하고자 합니다. 코드 import java.io.IOException fun main() { val score = readLine() ?: throw IOException() val grade = getGrade(score.toInt()) print(grade) } fun getGrade(score: Int): Char = when { score..
-
-
코틀린(kotlin) - 숫자 야구 게임프로젝트/Kotlin + TDD 2022. 10. 22. 00:01
개요 코틀린과 TDD에 친숙해지고자 자동차 경주 게임에 이어 숫자 야구 게임을 구현해 보겠습니다. 요구 사항 정리 랜덤으로 1~9짜리 서로 다른 3개의 수를 생성한다. 사용자에게 수를 입력받는다. 입력받은 수를 검증한다. 입력받은 3자리 수에서 볼, 스트라이크 개수를 구해서 반환한다. 구해진 볼, 스트라이크를 통해 출력 값을 결정한다. 스트라이크, 볼 0개 : "낫싱" 스트라이크 0~2개, 볼 0개 아님 : "n볼 n스트라이크" 스트라이크 3개 : "3 스트라이크" 정답 문구 출력 : "3개의 숫자를 모두 맞히셨습니다! 게임 종료" 스트라이크 3개가 나올 때까지 2~5 과정을 반복한다. README.md ### 요구 사항 - [ ] 랜덤으로 1~9까지의 숫자 3개 생성 - [ ] 사용자에게 3자리 숫자를..
-
[백준] 10809번 : 알파벳 찾기 - 코틀린(kotlin)알고리즘/백준 2022. 10. 21. 00:01
https://www.acmicpc.net/problem/10809 10809번: 알파벳 찾기 각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출 www.acmicpc.net 문제 해석 알파벳 소문자로 이루어진 단어 S가 주어집니다. 각 알파벳에 대해서 (a, b, c, d,....., x, y, z)가 처음 등장하는 위치를 공백으로 구분하여 출력합니다. 만약 알파벳이 단어에 포함되어 있지 않다면 -1을 출력하며, 단어의 첫 번째 글자는 0번째 위치부터 시작합니다. 문제 풀이 전 설계 단어의 길이는 100이 넘지 않기 때문에 단순 반복문을 통해서 해결하고자..
-
[백준] 10871번 : X보다 작은 수 - 코틀린(Kotlin)알고리즘/백준 2022. 10. 20. 00:01
https://www.acmicpc.net/problem/10871 10871번: X보다 작은 수 첫째 줄에 N과 X가 주어진다. (1 ≤ N, X ≤ 10,000) 둘째 줄에 수열 A를 이루는 정수 N개가 주어진다. 주어지는 정수는 모두 1보다 크거나 같고, 10,000보다 작거나 같은 정수이다. www.acmicpc.net 문제 해석 수열 A를 이루는 정수 N개가 주어집니다. 이때 중복을 허용하는지는 문제에서 나와있지 않은 것 같습니다. 수열 A에서 X보다 작은 수를 " "로 구분하여 출력하면 됩니다. 문제 풀이 전 설계 MutableList를 하나 선언하고 그 List에 X보다 작은 수를 스트림 filter를 활용하여 새로운 리스트로 만들어내고 출력해보고자 합니다. 이때 출력을 위해 Kotlin에 ..
-
[백준] 1001번 : A-B - 코틀린(Kotlin)카테고리 없음 2022. 10. 19. 00:01
https://www.acmicpc.net/problem/1001 1001번: A-B 두 정수 A와 B를 입력받은 다음, A-B를 출력하는 프로그램을 작성하시오. www.acmicpc.net 문제 해석 두 정수 A와 B를 입력받은 다음, A-B의 결과를 출력하는 간단한 프로그램입니다. 문제 풀이 전 설계 Kotlin에서 입력받는 방법을 알아보고 split을 통해 A와 B를 구분합니다. 코드 fun main() { val input : String = readLine() ?: throw IllegalStateException() val split = input.split(" ") val a = split[0].toInt() val b = split[1].toInt() println(a-b) } readLi..