오답 1
#include <iostream>
using namespace std;
int main(void)
{
int A, B, C = 0;
int totalCost = 0;
int totalIncome = -1;
int limit = 2100000000;
int gap = 0;
cin >> A;
cin >> B;
cin >> C;
if (A<=limit and B<=limit and C<=limit) // initial condition
{
if (B>=C)
{
cout << -1 << endl;
return 0;
}
int i = 1;
while (totalCost > totalIncome)
{
totalCost = A + (B * i);
totalIncome = C * i;
gap = totalCost - totalIncome;
i = i + 1;
}
cout << i << endl;
}
return 0;
}
오답 2
#include <iostream>
using namespace std;
int main(void)
{
int A, B, C = 0;
int totalCost = 0;
int totalIncome = -1;
int limit = 2100000000;
cin >> A;
cin >> B;
cin >> C;
if (A<=limit and A>=1 and B<=limit and B>=1 and C<=limit and C>=1) // initial condition
{
if (B>=C)
{
cout << -1 << endl;
return 0;
}
int i = 1;
while (totalCost > totalIncome)
{
totalCost = A + (B * i);
totalIncome = C * i;
i = i + 1;
}
cout << i << endl;
}
return 0;
}
정답
#include <iostream>
using namespace std;
int main(void)
{
int A, B, C = 0;
int limit = 2100000000;
cin >> A;
cin >> B;
cin >> C;
if (A<=limit and A>=1 and B<=limit and B>=1 and C<=limit and C>=1) // initial condition
{
if (B>=C)
{
cout << -1 << endl;
return 0;
}
cout << A/(C-B) + 1;
}
return 0;
}
'Computer Science > 백준 알고리즘' 카테고리의 다른 글
[백준] 1913번 달팽이 (C++) (0) | 2022.03.14 |
---|---|
[백준] 3의 배수 (파이썬) (0) | 2022.03.14 |
[백준] 1546번 평균 (C++) (0) | 2022.03.14 |
[백준] 1541번 잃어버린 괄호 (파이썬) (0) | 2022.03.14 |
[백준] 1436번 영화감독 숌 (파이썬) (0) | 2022.03.14 |