/* * 10137 - The Trip * 作者 仪冰 * 语言 C++ * QQ 974817955 * * 精度处理一小弄。n个学生,每个学生有一个花费, * 求出平均值,求小于平均值的总和(less), * 求出大于平均值的总和(greatly),最后再进行less和grealy比较,输出最大的。 */ #include#include #include using namespace std; const int SIZE = 1000; const double EXP = 1e-8; int main() { int nStudents = 0; //学生总数 double everyStudentCost[SIZE]; //存储每个学生的花费 double totalCost = 0.0; //花费总数 double average = 0.0; //平均值 double less = 0.0; //少于平均值 double greatly = 0.0; //多于平均值 while (cin >> nStudents) { if (nStudents == 0) { break; } //初始化 totalCost = 0.0; average = 0.0; less = 0.0; greatly = 0.0; //输入 for (int i=0; i > everyStudentCost[i]; } //求总花费 for (int i=0; igreatly) { cout.precision(2); cout.setf(ios::fixed | ios::showpoint); cout << "$" << less << endl; } else { cout.precision(2); cout.setf(ios::fixed | ios::showpoint); cout << "$" << greatly << endl; } } return 0; }