문제 출처:https://www.acmicpc.net/problem/1267
1267번: 핸드폰 요금
동호가 저번 달에 이용한 통화의 개수 N이 주어진다. N은 20보다 작거나 같은 자연수이다. 둘째 줄에 통화 시간 N개가 주어진다. 통화 시간은 10,000보다 작거나 같은 자연수이다.
www.acmicpc.net

해당 문제는 두가지 경우중 더 싼 요금제를 구하고 요금을 출력하는 문제입니다. input으로 들어온 시간을 30과 60으로 나눈 값에 + 1을 한 값으로 충분히 구할 수 있습니다.
코드는 다음과 같습니다:
#include <iostream>
#define Y_FEE 10
#define M_FEE 15
using namespace std ;
int main(){
ios::sync_with_stdio(false) ;
cin.tie(NULL) ; cout.tie(NULL) ;
int N, time, Y_total_fee = 0, M_total_fee = 0 ;
cin >> N ;
for(int i = 0 ; i < N ; i++){
cin >> time ;
Y_total_fee += (time/30+1)*Y_FEE ;
M_total_fee += (time/60+1)*M_FEE ;
}
if(Y_total_fee == M_total_fee)
cout << "Y M " << Y_total_fee << endl ;
else if(Y_total_fee < M_total_fee)
cout << "Y " << Y_total_fee << endl ;
else
cout << "M " << M_total_fee << endl ;
return 0 ;
}
해당 문제는 Github에서도 보실 수 있습니다:
https://github.com/gurcks8989/CodingTest/blob/master/BackJoon/HPS/P1267_Cellphone_Fee.cpp
GitHub - gurcks8989/CodingTest: CodingTest_study_with_c++
CodingTest_study_with_c++. Contribute to gurcks8989/CodingTest development by creating an account on GitHub.
github.com
훈수 및 조언은 언제든 환영입니다.
문제 출처:https://www.acmicpc.net/problem/1267
1267번: 핸드폰 요금
동호가 저번 달에 이용한 통화의 개수 N이 주어진다. N은 20보다 작거나 같은 자연수이다. 둘째 줄에 통화 시간 N개가 주어진다. 통화 시간은 10,000보다 작거나 같은 자연수이다.
www.acmicpc.net

해당 문제는 두가지 경우중 더 싼 요금제를 구하고 요금을 출력하는 문제입니다. input으로 들어온 시간을 30과 60으로 나눈 값에 + 1을 한 값으로 충분히 구할 수 있습니다.
코드는 다음과 같습니다:
#include <iostream>
#define Y_FEE 10
#define M_FEE 15
using namespace std ;
int main(){
ios::sync_with_stdio(false) ;
cin.tie(NULL) ; cout.tie(NULL) ;
int N, time, Y_total_fee = 0, M_total_fee = 0 ;
cin >> N ;
for(int i = 0 ; i < N ; i++){
cin >> time ;
Y_total_fee += (time/30+1)*Y_FEE ;
M_total_fee += (time/60+1)*M_FEE ;
}
if(Y_total_fee == M_total_fee)
cout << "Y M " << Y_total_fee << endl ;
else if(Y_total_fee < M_total_fee)
cout << "Y " << Y_total_fee << endl ;
else
cout << "M " << M_total_fee << endl ;
return 0 ;
}
해당 문제는 Github에서도 보실 수 있습니다:
https://github.com/gurcks8989/CodingTest/blob/master/BackJoon/HPS/P1267_Cellphone_Fee.cpp
GitHub - gurcks8989/CodingTest: CodingTest_study_with_c++
CodingTest_study_with_c++. Contribute to gurcks8989/CodingTest development by creating an account on GitHub.
github.com
훈수 및 조언은 언제든 환영입니다.