문제 출처 : https://www.acmicpc.net/problem/3512
언어 : Kotlin
문제 설명 :
You are one of the developers of software for a real estate agency. One of the functions you are to implement is calculating different kinds of statistics for flats the agency is selling. Each flat consists of different types of rooms: bedroom, bathroom, kitchen, balcony and others.
The cost of the flat is equal to the product of reduced total area and the cost of one square metre. Reduced total area is the total area of all rooms except for balconies plus one half of balconies total area.
You will be given some information about the area of each room in the flat and the cost of one square metre. You are to calculate the following values for the flat:
- the total area of all rooms;
- the total area of all bedrooms;
- the cost of the flat.
입력 :
The first line of the input file contains two integer numbers n (1 ≤ n ≤ 10) and c (1 ≤ c ≤ 100 000) — number of rooms in the flat and the cost of one square metre, respectively.
Each of the following n lines contains an integer number ai (1 ≤ ai ≤ 100) and a word ti — the area of i-th room and its type, respectively. Word ti is one of the following: “bedroom”, “bathroom”, “kitchen”, “balcony”, “other”.
출력 :
The first line of the output file should contain one integer number — the total area of all rooms of the flat. The second line of the output file should contain one integer number — the total area of bedrooms of the flat. The third line of the output file should contain one real number — the cost of the flat with precision not worse than 10^−6.
제한 사항 :
- 시간 제한 : 3초
- 메모리 제한 : 256MB
입출력 예 :
입력 | 출력 |
6 75000 8 other 3 bathroom 2 bathroom 10 kitchen 16 bedroom 7 balcony |
46 16 3187500 |
2 75123 10 kitchen 15 balcony |
25 0 1314652.5 |
풀이 :
import java.io.BufferedWriter
import java.io.OutputStreamWriter
fun main() = with(System.`in`.bufferedReader()) {
val bw = BufferedWriter(OutputStreamWriter(System.out))
val (n, c) = readLine().split(" ").map { it.toInt() }
val room = MutableList(n) {
val (a, t) = readLine().split(" ")
Pair(a.toDouble(), t)
}
val total = room.sumOf { it.first }
val bedroom = room.sumOf { if (it.second == "bedroom") it.first else 0.0 }
val price = room.map { if (it.second == "balcony") Pair(it.first / 2, it.second) else it }
bw.write("${total.toInt()}\n${bedroom.toInt()}\n${formatNumber(price.sumOf { it.first } * c)}")
bw.flush()
bw.close()
}
fun formatNumber(num: Double): String {
return if (num == num.toInt().toDouble()) {
num.toInt().toString()
} else {
num.toString()
}
}
'백준 > 문제' 카테고리의 다른 글
21942번: 부품 대여장 (1) | 2024.09.24 |
---|---|
24937번: SciComLove(2022) (1) | 2024.09.20 |
5013번: Death Knight Hero (0) | 2024.09.20 |
10940번: BASE16 인코딩 (0) | 2024.09.20 |
21771번: 가희야 거기서 자는 거 아니야 (0) | 2024.09.19 |
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!