Skip to content

Commit 26b9f35

Browse files
committed
Merge branch 'main' of ssh://github.com/AutoEver-CodingTest/Daily_Code
2 parents 59fb6f9 + cc612f3 commit 26b9f35

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <iostream>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
double N, P;
7+
int M;
8+
9+
// 대출을 갚는 함수
10+
double balance(double amount, int duration, double rates,
11+
double monthlyPayment) {
12+
double b = amount;
13+
for (int i = 0; i < duration; i++) {
14+
b *= 1.0 + (rates / 12) / 100.0;
15+
b -= monthlyPayment;
16+
}
17+
18+
return b;
19+
}
20+
21+
// 이분 탐색
22+
double payment(double amount, int duration, double rates) {
23+
// hi는 이제 한 달에 이자를 값을 상한액 = 월 이자가 포함된 금액
24+
double lo = 0, hi = amount * (1.0 + (rates / 12) / 100.0);
25+
26+
for (int iter = 0; iter < 100; ++iter) {
27+
double mid = (lo + hi) / 2.0;
28+
if (balance(amount, duration, rates, mid) <= 0) {
29+
hi = mid;
30+
} else {
31+
lo = mid;
32+
}
33+
}
34+
35+
return hi;
36+
}
37+
38+
int main(void) {
39+
int cc;
40+
41+
cin >> cc;
42+
for (int c = 0; c < cc; c++) {
43+
cin >> N >> M >> P;
44+
45+
printf("%.12lf\n", payment(N, M, P));
46+
}
47+
48+
return 0;
49+
}

0 commit comments

Comments
 (0)