您的位置:首页 > 其它

算法竞赛入门经典-课后练习-3-1-2分数统计

2013-12-27 16:00 399 查看


#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
struct Score
{
int size;
double points;
};
vector <Score> student;
vector <double> ans;
int main()
{

freopen("f:\\input.txt", "r", stdin);
//freopen("f:\\output1.txt", "w", stdout);
Score score;
while(cin >> score.points)
{
int flag = 1;
for(int i = 0; i < student.size(); ++i)
{
if(student[i].points == score.points)
{
student[i].size++;
flag  = 0;
break;
}
}
if(flag == 1)
{
score.size = 1;
student.push_back(score);
}
}
int max = 0;
for(int i = 0; i < student.size(); ++i)
{
if(student[i].size > max)
{
max = student[i].size;
}
}
for(int i = 0; i < student.size(); ++i)
{
if(student[i].size == max)
{
ans.push_back(student[i].points);
}
}
sort(ans.begin(), ans.end());
int first = 1;
for(int i = 0; i < ans.size(); ++i)
{
for(int j = 0; j != max; j++)
{
if(first)
{
printf("%.2lf", ans[i]);
first = 0;
}
else
{
printf(" %.2lf", ans[i]);
}
}
}
cout << endl;
cout <<"Time = " << (double)clock() / CLOCKS_PER_SEC << "s" << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: