U E D R , A S I H C RSS

The Trip/곽세환

  • O
  • double (를 들 9.03 9.029999999999... 됨). . 문 받는 방 .
  • double 느낌
  • - 돈( 는 돈 - ) 면 됨

~cpp 
#include <iostream>
using namespace std;

int main()
{
	int n;				//  
	int student[1000];	//   돈
	int total;			// 
	int aver;			// 
	int studentExchanged[1000];	//      돈
	int exchange;		//  는 돈
	int temp;
	int i, j;
	while (cin >> n && n != 0)
	{
		total = 0.0;
		exchange = 0.0;
		temp = 0.0;
		for (i = 0; i < n; i++)
		{
			double input;
			cin >> input;
			student[i] = (input + 0.005) * 100;
			total += student[i];
		}
		aver = total / n;
		for (i = 0; i < n; i++)
		{
			if (student[i] != aver)
				temp += student[i] - aver;
			studentExchanged[i] = aver;
		}
		for (i = 0; temp >= 1 && i < n; i++)
		{
			if (studentExchanged[i] == aver)
			{
				studentExchanged[i] = aver + 1;
				temp -= 1;
			}

		}

		// 
		for (i = 0; i < n - 1; i++)
			for (j = i + 1; j < n; j++)
			{
				if (student[i] > student[j])
				{
					int temp;
					temp = student[i];
					student[i] = student[j];
					student[j] = temp;
				}
				if (studentExchanged[i] > studentExchanged[j])
				{
					int temp;
					temp = studentExchanged[i];
					studentExchanged[i] = studentExchanged[j];
					studentExchanged[j] = temp;
				}

			}
		

		for (i = 0; i < n; i++)
		{
			if (studentExchanged[i] > student[i])
			{
				exchange += studentExchanged[i] - student[i];
			}
		}
	
		cout.setf(ios::fixed);
		cout.precision(2);
		cout << "$" << (exchange / 100.0) << endl;
		
	}
	
	return 0;
}


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:13
Processing time 0.0085 sec