您的位置:首页 > 其它

Problem F: 来算一下自己的成绩吧!

2017-05-13 13:42 274 查看
HomeWeb BoardProblemSetStandingStatusStatistics

Problem F: 来算一下自己的成绩吧!

Time Limit: 1 Sec  Memory Limit:
128 MB
Submit: 1269  Solved: 529

[Submit][Status][Web
Board]

Description

OJ是一个同学们又爱又恨的东东。老师在OJ上布置了作业,并且把作业成绩作为实验课程的成绩。马上就要结课了,小明想知道自己到底能得到多少分,所以他向老师请教分数的计算方法。老师告诉他,分数是这么算滴:

1. 对于某次作业,假设所有同学中Accpted题目数最多为X,小明Accpted题目数为Y,那么这次作业小明得分100Y/X。

2. 如果小明不幸错过了某次作业或者没有题目被Accpted,那么为0分。

3. 最终成绩是所有作业成绩的平均分。

好了,小明从OJ上下载了所有的standing,发现要想计算成绩还是挺麻烦的。所以,他向你求助,请你帮忙编个程序,算算分数。

Input

第1行N>0,表示本年级、本专业的学生数。

之后N行,每行是一个不含空白符的字符串,是一个学生的名字(假定没有重名,且姓名最多有10个字符)。

接着是M>0,表示老师总共布置的作业次数。

每次作业的输入中,第1行K>0,表示这次作业的standing中有提交记录的学生人数。之后K行是K个学生的姓名及其Accpted的题目数。

Output

第1行输出:NAME        TEST1  TEST2  TEST3 ...... FINAL。

其中,“TEST?”的个数等于作业次数,按照顺序依次输出,如上所示。

之后根据输入的专业学生姓名顺序,依次输出所有学生的每次作业成绩以及最终成绩。

所有输出左对齐。

成绩保留2位小数,且左对齐输出。

输出的每一列的第1个字符要对齐。

见样例。

Sample Input

5zhangsanlisiwangwuliuliudingqi32zhangsan 4lisi 85zhangsan 11lisi 7wangwu 4liuliu 3dingqi 43zhangsan 3lisi 10wangwu 7

Sample Output

NAME TEST1 TEST2 TEST3 FINALzhangsan 50.00 100.00 30.00 60.00 lisi 100.00 63.64 100.00 87.88 wangwu 0.00 36.36 70.00 35.45 liuliu 0.00 27.27 0.00 9.09 dingqi 0.00 36.36 0.00 12.12

HINT

Append Code

[Submit][Status][Web
Board]

한국어<  中文 فارسی English ไทย

All Copyright Reserved 2010-2011
SDUSTOJ TEAM
GPL2.0 2003-2011
HUSTOJ Project TEAM

Anything about the Problems, Please Contact Admin:admin

#include <iostream>
#include <iomanip>
using namespace std;
class Student
{
private:
string name;
double *score;
int *problemnums;
int num;
public:
~Student(){ delete []score; delete []problemnums; }
public:
void setname(string na)
{
name = na;
}
string getname()const
{
return name;
}

void setnum(int n)
{
num = n;
score = new double [num+1];
problemnums = new int[num+1];
for(int i = 0; i < num; i++)
{
score[i] = 0;
problemnums[i] = 0;
}
}
void setscore(int n, int num_max)
{
score
= 100 * ((double) problemnums
) / num_max;
}
double getscore(int n)const
{
return score
;
}
void setproblemnums(int n, int nu)
{
problemnums
=  nu;
}
double gettotalscore() const
{
double sum = 0;
for(int i = 0; i < num; i++)
sum+=score[i];
return sum / num;
}
};
Student &cmpname(Student *stu,string name,int n)
{
for(int i = 0; i < n; i++)
if(stu[i].getname() == name)
return stu[i];
}
int main()
{
int n, m; string name; int nums;
Student *stu;
cin >> n;
stu = new Student[n+1];
for(int i = 0; i < n; i++)
{
cin >> name;
stu[i].setname(name);
}
cin >> m;
for(int i = 0; i < n; i++)
stu[i].setnum(m);
for(int i = 0; i < m; i++)
{
int k, num_max;
cin >> k;
for(int j = 0; j < k; j++)
{
cin >> name >> nums;
cmpname(stu, name, n).setproblemnums(i,nums);
if(j == 0) num_max = nums;
if(num_max < nums) num_max = nums;
}
for(int j = 0; j < n; j++)
stu[j].setscore(i, num_max);
}

cout << setiosflags(ios::left) << setw(12) << "NAME";
for(int i = 0; i < m; i++)
{
cout << "TEST" << setiosflags(ios::left) << setw(3)<< i + 1;
}
cout << "FINAL" << endl;
for(int i = 0; i < n; i++)
{
cout << setiosflags(ios::left) << setw(12) << stu[i].getname();
for(int j = 0; j < m; j++)
cout << setiosflags(ios::left) << setw(7) << setprecision(2) << fixed << stu[i].getscore(j);
cout << setiosflags(ios::left) << setw(6) << setprecision(2) << fixed << stu[i].gettotalscore()  << endl;
}
delete []stu;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: