문제 링크입니다: https://www.acmicpc.net/problem/1267
1267번: 핸드폰 요금
첫째 줄에 싼 요금제의 이름을 출력한다. 그 후에 공백을 사이에 두고 요금이 몇 원 나오는지 출력한다. 만약 두 요금제의 요금이 모두 같으면 영식을 먼저 쓰고 민식을 그 다음에 쓴다. 영식은 Y로, 민식은 M으로 출력한다.
www.acmicpc.net
모듈러 연산을 알맞게 처리해야 AC를 받을 수 있는 수학 문제였습니다.
while문을 처리하는 것이 더 쉬웠겠지만 삼항연산자를 통해 코드를 간결화 시키는 것에 집중했습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
int Y = 0, M = 0; | |
for (int i = 0; i < N; i++) | |
{ | |
int callLength; | |
cin >> callLength; | |
Y += callLength / 30 * 10; | |
Y += (callLength + 1) % 30 ? 10 : 0; | |
M += callLength / 60 * 15; | |
M += (callLength + 1) % 60 ? 15 : 0; | |
} | |
if (Y > M) | |
{ | |
cout << "M " << M << "\n"; | |
} | |
else if (Y == M) | |
{ | |
cout << "Y M " << Y << "\n"; | |
} | |
else | |
{ | |
cout << "Y " << Y << "\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 1043번 거짓말 (0) | 2020.03.05 |
---|---|
백준 11328번 Strfry (0) | 2020.03.02 |
백준 10804번 카드 역배치 (0) | 2020.03.01 |
백준 2108번 통계학 (0) | 2020.02.24 |
백준 11375번 열혈강호 (0) | 2020.02.23 |