#55137: 解題思路(簡單的唷)


yp11452024@yphs.tp.edu.tw (704-03吳恩頤)


#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    int a=0,b=0,c=0,d=0,e=0;
    int x;
    int sum=0,cnt=0;

    while(cin >> x && x != 0){
        if(x==1) a++;
        if(x==2) b++;
        if(x==3) c++;
        if(x==4) d++;
        if(x==5) e++;

        sum += x;
        cnt++;
    }

    cout << "5 (";
    if(e<10) cout << " ";
    cout << e << ") |";
    for(int i=0;i<e;i++) cout << "=";
    cout << endl;

    cout << "4 (";
    if(d<10) cout << " ";
    cout << d << ") |";
    for(int i=0;i<d;i++) cout << "=";
    cout << endl;

    cout << "3 (";
    if(c<10) cout << " ";
    cout << c << ") |";
    for(int i=0;i<c;i++) cout << "=";
    cout << endl;

    cout << "2 (";
    if(b<10) cout << " ";
    cout << b << ") |";
    for(int i=0;i<b;i++) cout << "=";
    cout << endl;

    cout << "1 (";
    if(a<10) cout << " ";
    cout << a << ") |";
    for(int i=0;i<a;i++) cout << "=";
    cout << endl;

    cout << "Average rating: " <<fixed << setprecision(4);
    cout << (double)sum/cnt << endl;

    return 0;
}