# Uva12412 师兄帮帮忙

wa就wa吧，感觉自己是个废人了

#include<bits/stdc++.h>
using namespace std;
class Student
{
public:
string sid;
int cid,score1,score2,score3,score4,totalscore,rank;
string name;
Student(string sid,int cid,string name,int score1,int score2,int score3,int score4):sid(sid),cid(cid),score1(score1),score2(score2),score3(score3),score4(score4),name(name)
{

}
Student()
{

}//无参构造函数
friend istream& operator >>(istream& in,Student& x)//重定向输入流
{
in>>x.cid>>x.name>>x.score1>>x.score2>>x.score3>>x.score4;
x.totalscore=x.score1+x.score2+x.score3+x.score4;
x.rank=0;
return in;
}
friend ostream& operator <<(ostream& out,Student& x)
{
out<<x.rank<<" "<<x.sid<<" "<<x.cid<<" "<<x.name<<" "<<x.score1<<" "<<x.score2<<" "<<x.score3<<" ";
out<<x.score4<<" "<<x.totalscore<<" ";
printf("%.2f\n",x.totalscore/4.0);
return out;
}
};
vector<Student> myvector;
void paixu(void)
{
int rnk=1,cnt;
for(int i=400;i>=0;i--)
{
cnt=0;//cnt represents the number of students whose totalscore equals to i
for(auto &it:myvector)
{
if(it.totalscore==i)
{
it.rank=rnk;
cnt++;
}
}
rnk+=cnt;
}
}
void query(void)
{
paixu();//to calculate everyone's rank
double averagescore;
while(true)
{
printf("Please enter SID or name. Enter 0 to finish.\n");
string input;
cin>>input;
if(input=="0")
break;
if(isdigit(input[0]))//the input is student id
{
for(auto &it:myvector)
if(it.sid==input)
{
//printf("The rank of this student is %d\n",it.rank);
cout<<it;
}
}
else
{
for(auto &it:myvector)
if(it.name==input)
cout<<it;
}
}
}
{
while(true)
{
printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n");
Student temp;
string tempinput;
cin>>tempinput;
if(tempinput=="0")
break;
else
{
temp.sid=tempinput;
cin>>temp;
}
bool flag=false;
for(auto &it:myvector)
if(it.sid==temp.sid)
flag=true;
if(flag)
printf("Duplicated SID.\n");
else
myvector.push_back(temp);
}
}
void remove(void)
{
while(true)
{
int cnt=0;
printf("Please enter SID or name. Enter 0 to finish.\n");
vector<Student>::iterator it;
string input;
cin>>input;
if(input=="0")
break;
if(isdigit(input[0]))//the input is student id
{
for(it=myvector.begin();it!=myvector.end();)
{
if((*it).sid==input)
{
cnt++;
it=myvector.erase(it);
}
else
it++;
}
}
else//the input is a name
{
for(it=myvector.begin();it!=myvector.end();)
{
if((*it).name==input)
{
cnt++;
it=myvector.erase(it);
}
else
it++;
}
}
printf("%d student(s) removed.\n",cnt);
}
}

void ranking(void)
{
printf("Showing the ranklist hurts students' self-esteem. Don't do that.\n");
}
void statistics(void)
{
double average;
int num_passed,num_failed,id;
printf("Please enter class ID, 0 for the whole statistics.\n");
cin>>id;
//创建一个新的vector用来进行数据统计
vector<Student>stat;
stat.clear();
if(id==0)
{
for(auto &it:myvector)
stat.push_back(it);
}
else
{
for(auto &it:myvector)
{
if(it.cid==id)
stat.push_back(it);
}
}
//对每一门学科进行统计
{
average=num_passed=num_failed=0;
for(auto &it:stat)
{
average+=it.score1;
if(it.score1>=60)
num_passed++;
else
num_failed++;
}
printf("Chinese\n");
if(stat.size()==0)
printf("Average Score: 0.00\n");
else
printf("Average Score: %.2f\n",average/stat.size());
printf("Number of passed students: %d\n",num_passed);
printf("Number of failed students: %d\n\n",num_failed);
}
{
average=num_passed=num_failed=0;
for(auto &it:stat)
{
average+=it.score2;
if(it.score2>=60)
num_passed++;
else
num_failed++;
}
printf("Mathematics\n");
if(stat.size()==0)
printf("Average Score: 0.00\n");
else
printf("Average Score: %.2f\n",average/stat.size());
printf("Number of passed students: %d\n",num_passed);
printf("Number of failed students: %d\n\n",num_failed);
}
{
average=num_passed=num_failed=0;
for(auto &it:stat)
{
average+=it.score3;
if(it.score3>=60)
num_passed++;
else
num_failed++;
}
printf("English\n");
if(stat.size()==0)
printf("Average Score: 0.00\n");
else
printf("Average Score: %.2f\n",average/stat.size());
printf("Number of passed students: %d\n",num_passed);
printf("Number of failed students: %d\n\n",num_failed);
}
{
average=num_passed=num_failed=0;
for(auto &it:stat)
{
average+=it.score4;
if(it.score4>=60)
num_passed++;
else
num_failed++;
}
printf("Programming\n");
if(stat.size()==0)
printf("Average Score: 0.00\n");
else
printf("Average Score: %.2f\n",average/stat.size());
printf("Number of passed students: %d\n",num_passed);
printf("Number of failed students: %d\n\n",num_failed);
}
int num_pass[5]={0,0,0,0,0};//num_pass[i] represents the number of students who pass no less than i courses
//exception:num_pass[0] represents the number of students who failed all the tests
for(auto &it:stat)
{
int cnt=0;//统计每个人过了几门课
if(it.score1>=60)
cnt++;
if(it.score2>=60)
cnt++;
if(it.score3>=60)
cnt++;
if(it.score4>=60)
cnt++;
for(int i=1;i<=4;i++)
{
if(cnt>=i)
num_pass[i]++;
}
if(cnt==0)
num_pass[0]++;
}
printf("Overall:\n");
printf("Number of students who passed all subjects: %d\n",num_pass[4]);
printf("Number of students who passed 3 or more subjects: %d\n",num_pass[3]);
printf("Number of students who passed 2 or more subjects: %d\n",num_pass[2]);
printf("Number of students who passed 1 or more subjects: %d\n",num_pass[1]);
printf("Number of students who failed all subjects: %d\n\n",num_pass[0]);

}
{
int x;
bool flag=true;//控制何时退出
while(flag)
{
printf("Welcome to Student Performance Management System (SPMS).\n\n");
printf("2 - Remove\n");
printf("3 - Query\n");
printf("4 - Show ranking\n");
printf("5 - Show Statistics\n");
printf("0 - Exit\n\n");//watch out for this \n!!!
cin>>x;
switch(x)
{
break;
case 2:remove();
break;
case 3:query();
break;
case 4:ranking();
break;
case 5:statistics();
break;
case 0:flag=false;
}
}

}

int main(void)
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
myvector.clear();
return 0;
}


#### 算法竞赛入门经典（第2版）例题4-6 师兄帮帮忙 （A Typical Homework UVa 12412)

2014-08-02 08:07:27

#### 例题4-6　师兄帮帮忙 UVa12412

2016-10-19 13:36:14

#### UVa 12412 A Typical Homework(学生信息管理系统)

2014-08-03 15:45:44

#### UVA-12412A Typical Homework

2015-03-18 00:45:55

#### UVa 12412 - A Typical Homework

2015-02-14 11:20:30

#### UVA12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)【水题】

2016-09-03 08:02:26

#### UVA 12412 - A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) 模拟题 不好怎么评价

2017-01-09 18:50:45

#### UVA12412师兄帮帮忙

2018-02-11 11:59:29

#### [uva 12412]A Typical Homework(师兄帮帮忙)

2015-10-01 15:40:58

#### 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 师兄帮帮忙 Uva12412

2016-08-03 10:16:41