반응형
https://www.acmicpc.net/problem/18330
18330번: Petrol
The input consists of two lines. The first line contains an integer n (0 ⩽ n ⩽ 200), specifying the amount of petrol that will be used in the next month. The second line contains an integer k (0 ⩽ k ⩽ 360), showing the quota left in Mahya’s fuel
www.acmicpc.net
간단한 산수문제였습니다.
📕 풀이방법
📔 입력 및 초기화
다음달에 쓸 예정인 리터수 usePlan, 이번달에 쓰고 남은 리터수 leftLiter를 선언 후 입력받습니다.
📔 풀이과정
두 가지 경우로 나뉩니다.
1. 모두 할인 가능한 경우 : 다음달에 quota는 올해 남은 리터수 leftLister + 다음달에 받을 60L입니다. usePlan이 이 값 이하라면 모두 할인 가능합니다.
2. 일부 할인 가능한 경우 : 60 + leftLiter만큼은 할인 받을 수 있으나 그 외에는 할인 받을 수 없어 3000원의 값이 적용됩니다.
📕 Code
#include <bits/stdc++.h>
using namespace std;
int usePlan, leftLiter, availableLiter;
int main(){
cin >> usePlan >> leftLiter;
availableLiter = 60 + leftLiter;
if(usePlan <= availableLiter) cout << usePlan * 1500;
else cout << availableLiter * 1500 + (usePlan - availableLiter) * 3000;
}
'Algorithm > Math' 카테고리의 다른 글
(C++) - 백준(BOJ) 21335 : Another Eruption (0) | 2021.11.12 |
---|---|
(C++) - 백준(BOJ) 21185 : Some Sum (0) | 2021.11.11 |
(C++) - 백준(BOJ) 18005 : Even or Odd? (0) | 2021.10.31 |
(C++) - 백준(BOJ) 16693 : Pizza Deal (0) | 2021.10.27 |
(C++) - 백준(BOJ) 16648 : Accumulator Battery (0) | 2021.10.26 |