반응형
```
백준 25527번 Counting Peaks of Infection Kotlin 구현해보기
```
이번 글을 통해 배워갈 내용
- 백준 25527번 풀이
https://www.acmicpc.net/problem/25527
25527번: Counting Peaks of Infection
For the new infectious disease, COVID-99, numbers of new positive cases of PCR tests conducted in the city are reported daily. You are requested by the municipal public relations department to write a program that counts the number of the peaks so far of t
www.acmicpc.net
백준 25527번 Counting Peaks of Infection은
난이도 브론즈 등급의 문제로서
그래프가 주어지면 해당 그래프의 정점의 개수를 구해주면 되는 문제입니다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
각 데이터별로
데이터 사이즈를 입력받고
0이면 종료하고
아닌 경우 데이터를 입력받습니다.
데이터가 정점인 경우 카운팅하고
아닌 경우 넘어가서
정점의 개수를 구한 다음 출력해줍니다.
fun main(args: Array<String>) {
val sb = StringBuilder()
while (true) {
// 입력
val dataSize = readln().toInt()
if (dataSize == 0) {
break
}
val dataList = readln().split(" ").map { it.toInt() }
// 연산
sb.append(findPeakSize(dataSize, dataList)).append("\n")
}
sb.setLength(sb.length - 1)
print(sb.toString())
}
fun findPeakSize(dataSize: Int, dataList: List<Int>): Int {
var peakSize = 0
for (i in 1 until dataSize - 1) {
if (dataList[i] > dataList[i - 1] && dataList[i] > dataList[i + 1]) {
peakSize++
}
}
return peakSize
}
// https://codemasterkimc.tistory.com/
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩 하시길 바랍니다 ~ :)
728x90
반응형
'Kotlin > Kotlin 알고리즘' 카테고리의 다른 글
백준 25641번 균형 잡힌 소떡소떡 (0) | 2022.10.04 |
---|---|
백준 25642번 젓가락 게임 (0) | 2022.10.04 |
백준 25551번 멋쟁이 포닉스 Kotlin 구현해보기 (2) | 2022.10.03 |
백준 25625번 샤틀버스 Kotlin 구현해보기 (0) | 2022.10.03 |
백준 25704번 출석 이벤트 Kotlin 구현해보기 (2) | 2022.10.03 |