Sicily 1817. 校歌手大奖赛

来源:互联网 发布:淘宝买中药靠谱么 编辑:程序博客网 时间:2024/05/17 06:37

它题目要求用类实现, 那我就用了个类实现了. 好简单

不多说

// Problem#: 1817// Author#: Reid Chan#include <iostream>#include <iomanip>#include <stdio.h>using namespace std;class Competitor {private:    double sum;    double cnt;    double max;    double min;public:    Competitor() {        sum = 0;        cnt = 0;        max = -1;        min = 101;    }    double average() {        return (sum - max - min) / (cnt - 2);    }    void set(int s) {        sum += s;        ++cnt;        if (s > max) {            max = s;        }        if (s < min) {            min = s;        }    }};int main() {    int t;    cin >> t;    while (t--) {        int n, m;        scanf("%d%d", &n, &m);        Competitor *cpt = new Competitor [m];        for (int i = 0; i < n; ++i) {            int score;            for (int j = 0; j < m; ++j) {                scanf("%d", &score);                cpt[j].set(score);            }        }        for (int j = 0; j < m; ++j) {//          cout << fixed << setprecision(2) << cpt[j].average() << endl;            printf("%.2f\n", cpt[j].average());        }    }    return 0;}                                 


0 0
原创粉丝点击