본문 바로가기
  • Let's study
PS/백준

[C++] 백준 25881: Electric Bill

by 코딩고수이고파 2023. 5. 21.

문제

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

 

25881번: Electric Bill

The first input line contains two integers (each between 2 and 20, inclusive), indicating the rate/KWH for the first 1000 KWH and the rate/KWH for the additional usage, respectively. The next input line contains a positive integer, n, indicating the number

www.acmicpc.net

 

해결방법

입력받은 고객의 에너지 소비량에서 1000은 기본 요율, 1000을 뺀 나머지는 추가 요율을 적용하여 출력하면 된다.

 

코드

#include<iostream>

using namespace std;

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

	int a, b, n;
	cin >> a >> b >> n;

	int energy;
	for (int i = 0; i < n; i++) {
		cin >> energy;

		int fee;
		if (energy >= 1000)
			fee = 1000 * a + (energy - 1000)*b;
		else
			fee = energy * a;

		cout << energy << ' ' << fee << '\n';
	}

	return 0;
}

'PS > 백준' 카테고리의 다른 글

[C++] 백준 1238: 파티  (1) 2023.10.04
[C++] 백준 25828: Corona Virus Testing  (0) 2023.05.22
[C++] 백준 9772: Quadrants  (0) 2023.05.20
[C++] 백준 25893: Majestic 10  (0) 2023.05.19
[C++] 백준 27880: Gahui and Soongsil University statio  (0) 2023.05.18

댓글