#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
namespace
{
struct seiseki
{
std::string namae;
int kokugo;
int sugaku;
};
struct kamoku
{
std::string kamoku_mei;
int seiseki::*score_ptr;
};
std::vector<seiseki> seiseki_data
{
{"太郎", 74, 93},
{"次郎", 78, 82},
{"三郎", 94, 68}
};
std::vector<kamoku> kamoku_list
{
{"KOKUGO", &seiseki::kokugo},
{"SUGAKU", &seiseki::sugaku}
};
int keisan_kojin_gokei(seiseki score)
{
return score.kokugo + score.sugaku;
}
} // namespace
int main()
{
cout << "namae ";
for ( auto kamoku : kamoku_list )
cout << setw(8) << kamoku.kamoku_mei;
cout << " gokei" << endl;
cout << fixed << setprecision(1);
for ( auto score : seiseki_data )
{
cout << setw(8) << score.namae
<< setw(8) << score.kokugo
<< setw(8) << score.sugaku
<< " "
<< setw(8) << keisan_kojin_gokei(score)
<< endl;
}
cout << " ";
for ( auto kamoku_idx = 0; kamoku_idx < kamoku_list.size(); kamoku_idx++ )
{
double total = 0.0;
for ( auto score : seiseki_data )
{
total += score.*(kamoku_list[kamoku_idx].score_ptr);
}
cout << setw(8) << total / seiseki_data.size();
}
double total = 0.0;
for ( auto score : seiseki_data )
total += keisan_kojin_gokei(score);
cout << setw(8) << total / seiseki_data.size();
cout << endl;
cout << endl;
for ( auto kamoku : kamoku_list )
{
cout << "<" << kamoku.kamoku_mei << ">" << endl;
std::sort(seiseki_data.begin(), seiseki_data.end(),
[kamoku](seiseki lhs, seiseki rhs)
{
return lhs.*(kamoku.score_ptr) > rhs.*(kamoku.score_ptr);
}
);
auto rank = 0;
for ( auto score : seiseki_data )
{
// std::printf(" %d %s %d\n", ++rank, score.namae.c_str(), score.*(kamoku.score_ptr));
cout << ++rank << " " << score.namae << " " << score.*(kamoku.score_ptr) << endl;
}
cout << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1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