오답 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;
}

+ Recent posts