언어/C++
[백준1267] 핸드폰 요금
연나연
2023. 12. 28. 22:51

<문제풀이>
1. "동호의 저번 달 통화 개수" N 을 입력받는다
2. N의 개수 만큼 통화시간을 입력받는다. (for문 이용)
3. 영식요금제가 적용된 요금 구한다
4. 민식요금제가 적용된 요금 구한다
5. 영식요금제 적용 요금과 민식요금제 적용 요금 크기 비교하여 더 작은 값을 알아낸다
-가격 같은 경우 예외처
6. 더 작은 값의 요금제를 출력하고 요금도 출력한다.
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, time, yPrice=0, mPrice=0;
string result;
int price = 0;
//1. "동호의 저번 달 통화 개수" N 을 입력받는다
cin >> N;
//2. N의 개수 만큼 통화시간을 입력받는다. (for문 이용)
for (int i = 0; i < N; i++) {
cin >> time;
int yPrice_temp = (time / 30 + 1) * 10;
yPrice += yPrice_temp;
int mPrice_temp = (time / 60 + 1) * 15;
mPrice += mPrice_temp;
}
if (yPrice == mPrice) {
cout << "Y M " << yPrice;
}
else {
price = (yPrice < mPrice) ? yPrice : mPrice;
result = (yPrice < mPrice) ? "Y" : "M";
cout << result << " " << price;
}
return 0;
}
