PE,弃疗了。
#include <iostream>
#include <string>
#include <cstdio>
#include <iomanip>
#include <algorithm>
using namespace std;
struct stu{
int CID,C[4],SUM=0;
string SID,NAME;
};
string wel[7]={"Welcome to Student Performance Management System (SPMS).",
"1 - Add",
"2 - Remove",
"3 - Query",
"4 - Show ranking",
"5 - Show Statistics",
"0 - Exit"};
string info[7]={"Duplicated SID.",
"Please enter the SID, CID, name and four scores. Enter 0 to finish.",
"Please enter SID or name. Enter 0 to finish.",
"Showing the ranklist hurts students' self-esteem. Don't do that.",
"Please enter class ID, 0 for the whole statistics.",
" student(s) removed.",
"Showing the ranklist hurts students' self-esteem. Don't do that."};
string course[4]={"Chinese",
"Mathematics",
"English",
"Programming"};
void welcome()
{
int i;
for(i=0;i<7;i++){
cout<<wel[i]<<endl;
if(!i)
cout<<endl;
}
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
stu s[1000];
int n=0,c[4],k,cid,i,j,flag,count;
string sid,name,match;
while(1){
welcome();
cout<<endl;
cin>>k;
if(!k)
break;
else if(k==1){
while(1){
cout<<info[1]<<endl;
flag=0;
cin>>sid;
if(sid=="0")
break;
else
cin>>cid>>name>>c[0]>>c[1]>>c[2]>>c[3];
for(i=0;i<n;i++)
if(s[i].SID==sid){
cout<<info[0]<<endl;
flag=1;
break;
}
if(flag)
continue;
else{
s[n].SID=sid,s[n].CID=cid,s[n].NAME=name,s[n].C[0]=c[0],s[n].C[1]=c[1],s[n].C[2]=c[2],s[n].C[3]=c[3],s[n].SUM=c[0]+c[1]+c[2]+c[3];
n++;
}
}
}
else if(k==2){
while(1){
cout<<info[2]<<endl;
cin>>match;
if(match=="0")
break;
count=0;
for(i=0;i<n;i++){
if((s[i].NAME==match&&s[i].SID!="0")||s[i].SID==match){
count++;
s[i].SID="0";
}
}
cout<<count<<info[5]<<endl;
}
}
else if(k==3){
while(1){
cout<<info[2]<<endl;
cin>>match;
if(match=="0")
break;
flag=0;
for(i=0;i<n;i++){
if((s[i].NAME==match&&s[i].SID!="0")||s[i].SID==match){
count=1,flag=1;
for(j=0;j<n;j++){
if(s[j].SID!="0"&&s[j].SUM>s[i].SUM)
count++;
}
if(flag)
cout<<count<<' '<<s[i].SID<<' '<<s[i].CID<<' '<<s[i].NAME<<' '<<s[i].C[0]<<' '<<s[i].C[1]<<' '<<s[i].C[2]<<' '<<s[i].C[3]<<' '<<s[i].SUM<<' '<<fixed<<setprecision(2)<<(double)s[i].SUM/4+1e-6<<endl;
}
}
}
}
else if(k==4){
cout<<info[3]<<endl;
}
else if(k==5){
cout<<info[4]<<endl;
cin>>cid;
int total[4]={0},coursepass[4]={0},totalpass[5]={0},num=0;
for(i=0;i<n;i++){
if(s[i].SID!="0"&&(s[i].CID==cid||!cid)){
count=0,num++;
for(j=0;j<4;j++){
if(s[i].C[j]>=60)
count++,coursepass[j]++;
total[j]+=s[i].C[j];
}
totalpass[count]++;
}
}
for(i=0;i<4;i++){
cout<<course[i]<<endl;
cout<<"Average Score: "<<fixed<<setprecision(2)<<(double)total[i]/max(num,1)+1e-6<<endl;
cout<<"Number of passed students: "<<coursepass[i]<<endl;
cout<<"Number of failed students: "<<num-coursepass[i]<<endl;
cout<<endl;
}
cout<<"Overall: "<<endl;
cout<<"Number of students who passed all subjects: "<<totalpass[4]<<endl;
cout<<"Number of students who passed 3 or more subjects: "<<totalpass[3]+totalpass[4]<<endl;
cout<<"Number of students who passed 2 or more subjects: "<<totalpass[2]+totalpass[3]+totalpass[4]<<endl;
cout<<"Number of students who passed 1 or more subjects: "<<totalpass[1]+totalpass[2]+totalpass[3]+totalpass[4]<<endl;
cout<<"Number of students who failed all subjects: "<<totalpass[0]<<endl;
cout<<endl;
}
}
return 0;
}