감 ¶
2005/02/19 Accepted 0:00.029 64
¶
~cpp
// no10137 - The Trip
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
const int MAX = 100;
int exchangeMoney(const int * cost, const int n);
void showExchange(const int * ex, const int count);
int main() // cent 계
{
int n; //
char money[7]; //
int exchangeCost[MAX]; // 교값
int i, c;
int count = 0;
while (cin >> n)
{
if (n == 0)
break;
cin.get();
int costs[1000]; // 각
for (i=0; i<n; i++)
{
c = 0;
while (cin.peek() != 'n')
{
if (cin.peek() == '.')
cin.get();
else
cin.get(money[c++]);
}
money[c] = '';
cin.get();
costs[i] = atoi(money);
}
exchangeCost[count++] = exchangeMoney(costs, n);
}
showExchange(exchangeCost, count);
return 0;
}
int exchangeMoney(const int * cost, const int n)
{
int sum = 0; // 계
int aver, r; // 균,
int i;
for (i=0; i<n; i++)
sum += cost[i];
aver = sum/n;
r = sum%n;
int exchange = 0;
for (i=0; i<n; i++)
{
if (cost[i] > aver)
{
exchange += cost[i] - aver;
if (r > 0)
{
exchange--;
r--;
}
}
}
return exchange;
}
void showExchange(const int * ex, const int count)
{
int i;
int dollor, cent;
for (i=0; i<count; i++) // dollor
{
dollor = ex[i]/100;
cent = ex[i]%100;
cout << "$" << dollor << ".";
if (cent < 10)
cout << "0" << cent;
else
cout << cent;
cout << endl;
}
}










