```
백준 1267번 핸드폰 요금 JAVA 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 1267번 풀이
https://www.acmicpc.net/problem/1267
1267번: 핸드폰 요금
동호가 저번 달에 이용한 통화의 개수 N이 주어진다. N은 20보다 작거나 같은 자연수이다. 둘째 줄에 통화 시간 N개가 주어진다. 통화 시간은 10,000보다 작거나 같은 자연수이다.
www.acmicpc.net
백준 1267번 핸드폰 요금은
난이도 브론즈 등급의 문제로서
Y 요금제는 30초마다 10원씩 청구되고 (0초면 10원, 30초면 20원)
M 요금제는 60초마다 15원씩 청구될 때 (0초면 15원, 60초면 30원)
핸드폰 통화 횟수와
핸드폰 통화 길이들을 받고
더 싼 요금제와 해당되는 요금을 출력해주면 됩니다.
같다면 Y M과 함께 요금을 출력해주면 됩니다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
입력을 받고
정해진 조건에 맞춰서 요금제 계산을 해준 다음
조건에 맞게 출력해주면 되는
문제입니다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) throws IOException {
// BufferedReader Object 생성
final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
final StringBuilder sb = new StringBuilder();
// 입력
final int callCnt = Integer.parseInt(br.readLine());
List<Integer> callLengths = Arrays.stream(br.readLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
int yPlanPriceTotal = IntStream.range(0, callCnt).map(t -> planPrice(callLengths.get(t), 30, 10)).sum();
int mPlanPriceTotal = IntStream.range(0, callCnt).map(t -> planPrice(callLengths.get(t), 60, 15)).sum();
if (yPlanPriceTotal > mPlanPriceTotal) {
sb.append("M ").append(mPlanPriceTotal);
} else if (yPlanPriceTotal < mPlanPriceTotal) {
sb.append("Y ").append(yPlanPriceTotal);
} else {
sb.append("Y M ").append(yPlanPriceTotal);
}
// 출력
System.out.print(sb);
// 생성된 BufferedReader 반환
br.close();
}
private static int planPrice(int callTime, int timeInterval, int priceRate) {
return ((callTime / timeInterval) + 1) * priceRate;
}
}
//codemasterkimc.tistory.com [김씨의 코딩 스토리]
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩 하시길 바랍니다 ~ :)
728x90
'Java > Java 알고리즘' 카테고리의 다른 글
| 백준 1252번 이진수 덧셈 JAVA 구현해보기 (0) | 2022.05.07 |
|---|---|
| 백준 1225번 이상한 곱셈 JAVA 구현해보기 (0) | 2022.05.07 |
| 백준 1284번 집 주소 JAVA 구현해보기 (0) | 2022.05.07 |
| 백준 1247번 부호 JAVA 구현해보기 (0) | 2022.05.07 |
| 백준 24365번 ПЧЕЛИЧКАТА МАЯ JAVA 구현해보기 (0) | 2022.05.07 |