※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 6842번 문제인 Deal or No Deal Calculator이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/6842
6842번: Deal or No Deal Calculator
The user must input a number n (1 n < 10) which indicates how many cases have been opened so far, followed by a list of n integers between 1 and 10 representing the values in the game that have been eliminated, followed by the “Banker’s” offer. For
www.acmicpc.net
문제의 요구에 따라 (남은 briefcase에 든 돈의 총합) / (남은 briefcase의 개수) 과 (deal로 제안된 값)의 대소 비교에 따라 "deal" 또는 "no deal"을 출력하는 프로그램을 작성하자.
부동 소수점 오차가 걱정되는 경우, 남은 briefcase의 개수는 항상 양의 정수이므로 위 대소 비교 결과는 (남은 briefcase에 든 돈의 총합)과 (deal로 제안된 값) * (남은 briefcase의 개수)의 대소 비교 결과와 같음을 이용하는 것으로 실수 연산을 피할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int N, cnt, total = 1691600, deal;
int val[11] = { 0,100,500,1000,5000,10000,25000,50000,100000,500000,1000000 };
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N; cnt = 10 - N;
while (N--) {
int x; cin >> x;
total -= val[x];
}
cin >> deal;
if (deal * cnt > total) cout << "deal";
else cout << "no deal";
}
'BOJ' 카테고리의 다른 글
[BOJ 28285 // C++] 육각형 순회 (0) | 2023.11.18 |
---|---|
[BOJ 6844 // C++] Keep on Truckin' (0) | 2023.11.17 |
[BOJ 2713 // C++] 규현이의 사랑을 담은 문자메시지 (2) | 2023.11.15 |
[BOJ 2718 // C++] 타일 채우기 (0) | 2023.11.14 |
[BOJ 15311 // C++] 약 팔기 (1) | 2023.11.13 |