※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 5157번 문제인 Bailout Bonus이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/5157
5157번: Bailout Bonus
In order to prevent many financial companies from collapsing, the US Government (and several other governments) “bailed them out”, in the sense that they provided multi-billion dollar emergency loans. After this happened, several of the companies went
www.acmicpc.net
문제를 요약하면, 이 문제는 bailed out된 회사들의 각 보너스의 r%(소수점 아래 버림)를 합한 값을 구하는 문제이다. 이는 조건문과 반복문을 적절히 이용해 구현할 수 있다.
각 데이터셋에 대한 답을 출력할 때 사이에 각 답 사이에 빈 줄이 하나 포함되어야 함에 유의하자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <cstring>
using namespace std;
int T;
int company[501];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
for (int t = 1; t <= T; t++) {
int ans = 0;
memset(company, 0, sizeof(company));
int C, B, n, r; cin >> C >> B >> n >> r;
while (B--) {
int x; cin >> x;
company[x] = 1;
}
while (n--) {
int c, p; cin >> c >> p;
if (company[c]) ans += p * r / 100;
}
cout << "Data Set " << t << ':' << '\n' << ans << '\n' << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 9698 // C++] SAHUR & IMSA’ (0) | 2023.01.06 |
---|---|
[BOJ 24311 // C++] ПЪТУВАНЕ (0) | 2023.01.06 |
[BOJ 25495 // C++] 에어팟 (0) | 2023.01.05 |
[BOJ 22093 // C++] Соцопрос (0) | 2023.01.05 |
[BOJ 11176 // C++] In the Shower (0) | 2023.01.05 |