※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 26332번 문제인 Buying in Bulk이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/26332
26332번: Buying in Bulk
The first input line contains a positive integer, n, indicating the number of customers to check. The customers are on the following n input lines, one customer per line. Each line provides two integers; the first integer c (1 ≤ c ≤ 100) is the number
www.acmicpc.net
할인을 적용하기 전, 가격이 p인 물건을 c개 구입했을 때 내야하는 값은 p*c이다.
위의 가격에서 c-1개의 물건에 대해 각각 2만큼 할인을 적용하면, 즉 위의 값에서 2*(c-1)를 빼주면 문제의 답을 구해낼 수 있다. c = 1에 대해서도(할인이 없는 경우에도) 이와 같은 식으로 답이 제대로 구해짐을 확인하자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int T;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
int c, p; cin >> c >> p;
cout << c << ' ' << p << '\n' << p * c - 2 * (c - 1) << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 2758 // C++] 로또 (0) | 2022.12.17 |
---|---|
[BOJ 6841 // C++] I Speak TXTMSG (0) | 2022.12.17 |
[BOJ 6840 // C++] Who is in the middle? (0) | 2022.12.17 |
[BOJ 26340 // C++] Fold the Paper Nicely (1) | 2022.12.17 |
[BOJ 6845 // C++] Federal Voting Age (0) | 2022.12.17 |