※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 15083번 문제인 Life Savings이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/15083 

 

15083번: Life Savings

Input consists of two lines. The first line starts with three positive integers p1 p2 p3 (p1, p2, p3 ≤ 1000) which are the prices of three objects to be purchased. The second line contains three positive integers c1 c2 c3 (c1, c2, c3 ≤ 100) where c1 is

www.acmicpc.net

전체 가격 할인쿠폰을 사용하는 것과 두 물건에 대해 각각 하나의 할인쿠폰을 사용하는 것 중 어느 것이 더 이득인지를 판단하는 문제이다.

 

두 개의 할인쿠폰을 이용할 때 두 쿠폰을 같은 물건에 사용하는 경우는 고려하지 않음에 유의하자. 또한, 더 비용이 큰 물건에 더 할인율이 높은 쿠폰을 사용하는 것이 항상 이득임을 관찰해 문제를 해결하자.

 

아래는 제출한 소스코드이다.

#include <iostream>
#include <algorithm>
using namespace std;

int arr[3];
int coupon[3];
int val1, val2;
int X, Y;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	for (int i = 0; i < 3; i++) {
		cin >> arr[i];
		arr[i] *= 100;
	}
	sort(arr, arr + 3);
	
	for (int i = 0; i < 3; i++) cin >> coupon[i];
	if (coupon[1] > coupon[2]) swap(coupon[1], coupon[2]);

	val1 = (arr[0] + arr[1] + arr[2]) * (100 - coupon[0]) / 100;
	val2 = arr[0] + arr[1] * (100 - coupon[1]) / 100 + arr[2] * (100 - coupon[2]) / 100;

	if (val1 < val2) {
		cout << "one ", val1 = (arr[0] + arr[1] + arr[2]) - val1;
		X = val1 / 100, Y = val1 % 100;
	}
	else {
		cout << "two ", val2 = (arr[0] + arr[1] + arr[2]) - val2; 
		X = val2 / 100, Y = val2 % 100;
	}

	cout << X << '.';
	if (Y < 10) cout << 0;
	cout << Y;
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 15429 // C++] Odd Gnome  (0) 2023.01.06
[BOJ 21679 // C++] Клавиатура  (0) 2023.01.06
[BOJ 11258 // C++] Thai Lottery Checking  (0) 2023.01.06
[BOJ 20374 // C++] Big Money  (0) 2023.01.06
[BOJ 24333 // C++] СРЕЩА НА ПРИЯТЕЛИ  (0) 2023.01.06

+ Recent posts