rt,孩纸调了 5.5 个小时了,球球哪位 dalao 救救孩纸吧 …
#include <bits/stdc++.h>
#define ll long long
#define isremove(x) stu[x].IsRemove
using namespace std;
const double eps = 1e-5;
struct student{
string name, sid;
ll cid, c, m, e, p, total;
bool IsRemove;
double average;
}stu[1000010];
ll op, now, cnt, score[1000010];
map<string, bool> visit;
map<string, vector<ll> > pos1; // name
map<string, vector<ll> > pos2; // sid
void print(ll qwq){
cout << stu[qwq].name << " " << stu[qwq].sid << endl;
printf("%lld %lld %lld %lld %lld %lld\n", stu[qwq].cid, stu[qwq].c, stu[qwq].m, stu[qwq].e, stu[qwq].p, stu[qwq].total);
cout << stu[qwq].IsRemove << endl;
printf("%.2lf\n", stu[qwq].average + eps);
}
void welcome(){
printf("Welcome to Student Performance Management System (SPMS).\n\n");
printf("1 - Add\n");
printf("2 - Remove\n");
printf("3 - Query\n");
printf("4 - Show ranking\n");
printf("5 - Show Statistics\n");
printf("0 - Exit\n\n");
}
void Add(){
string s, name;
ll CID, chi, math, eng, pro;
while(1){
printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n");
cin >> s;
if(s == "0") break;
cin >> CID >> name >> chi >> math >> eng >> pro;
if(visit[s]){printf("Duplicated SID.\n"); continue;}
stu[++now].name = name;
stu[now].sid = s;
stu[now].cid = CID;
stu[now].c = chi; stu[now].m = math; stu[now].e = eng; stu[now].p = pro;
stu[now].total = chi + math + eng + pro;
stu[now].IsRemove = 0;
stu[now].average = stu[now].total / 4.0;
pos1[name].emplace_back(now);
pos2[s].emplace_back(now);
visit[s] = 1;
}
}
void Remove(){
string s;
while(1){
printf("Please enter SID or name. Enter 0 to finish.\n");
cin >> s;
if(s == "0") break;
if(isdigit(s[0])){
printf("%lld student(s) removed.\n", pos1[s].size());
for(auto pos : pos1[s])
stu[pos].IsRemove = 1;
}else{
printf("%lld student(s) removed.\n", pos2[s].size());
for(auto pos : pos2[s])
stu[pos].IsRemove = 1;
}
}
}
void Query(){
string s;
while(1){
printf("Please enter SID or name. Enter 0 to finish.\n");
cin >> s;
if(s == "0") break;
cnt = 0;
for(ll i = 1; i <= now; i++)
if(!isremove(i)) score[++cnt] = stu[i].total;
sort(score + 1, score + cnt + 1);
if(isdigit(s[0]))
for(auto pos : pos2[s])
if(!isremove(pos)){
ll rank = lower_bound(score + 1, score + cnt + 1, stu[pos].total) - score;
cout << rank << " " << stu[pos].sid << " ";
cout << stu[pos].cid << " " << stu[pos].name << " ";
printf("%lld %lld %lld %lld %lld %.2lf\n", stu[pos].c, stu[pos].m, stu[pos].e, stu[pos].p, stu[pos].total, stu[pos].average + eps);
}
else
for(auto pos : pos1[s])
if(!isremove(pos)){
ll rank = lower_bound(score + 1, score + cnt + 1, stu[pos].total) - score;
cout << rank << " " << stu[pos].sid << " ";
cout << stu[pos].cid << " " << stu[pos].name << " ";
printf("%lld %lld %lld %lld %lld %.2lf\n", stu[pos].c, stu[pos].m, stu[pos].e, stu[pos].p, stu[pos].total, stu[pos].average + eps);
}
}
}
void Show_ranking(){
printf("Showing the ranklist hurts students\' self-esteem. Don\'t do that.\n");
}
void Show_Statistics(){
printf("Please enter class ID, 0 for the whole statistics.\n");
ll num;
cin >> num;
ll cnt = 0;
double a1 = 0, a2 = 0, a3 = 0, a4 = 0;
ll p1 = 0, p2 = 0, p3 = 0, p4 = 0;
ll f1 = 0, f2 = 0, f3 = 0, f4 = 0;
ll t4 = 0, t3 = 0, t2 = 0, t1 = 0, t0 = 0;
for(ll i = 1; i <= now; i++)
if(!isremove(i) && (!now ? 1 : stu[i].cid == num)){
ll temp = 0;
cnt++;
a1 += stu[i].c;
if(stu[i].c > 59) p1++, temp++;
else f1++;
a2 += stu[i].m;
if(stu[i].m > 59) p2++, temp++;
else f2++;
a3 += stu[i].e;
if(stu[i].e > 59) p3++, temp++;
else f3++;
a4 += stu[i].p;
if(stu[i].p > 59) p4++, temp++;
else f4++;
if(!temp) t0++;
if(temp == 1) t1++;
if(temp == 2) t2++;
if(temp == 3) t3++;
if(temp == 4) t4++;
t3 += t4; t2 += t3; t1 += t2;
}
a1 /= cnt; a2 /= cnt; a3 /= cnt; a4 /= cnt;
a1 += eps; a2 += eps; a3 += eps; a4 += eps;
printf("Chinese\n");
printf("Average Score: %.2lf\n", a1);
printf("Number of passed students: %lld\n", p1);
printf("Number of failed students: %lld\n\n", f1);
printf("Mathematics\n");
printf("Average Score: %.2lf\n", a2);
printf("Number of passed students: %lld\n", p2);
printf("Number of failed students: %lld\n\n", f2);
printf("English\n");
printf("Average Score: %.2lf\n", a3);
printf("Number of passed students: %lld\n", p3);
printf("Number of failed students: %lld\n\n", f3);
printf("Programming\n");
printf("Average Score: %.2lf\n", a4);
printf("Number of passed students: %lld\n", p4);
printf("Number of failed students: %lld\n\n", f4);
printf("Overall:\n");
printf("Number of students who passed all subjects: %lld\n", t4);
printf("Number of students who passed 3 or more subjects: %lld\n", t3);
printf("Number of students who passed 2 or more subjects: %lld\n", t2);
printf("Number of students who passed 1 or more subjects: %lld\n", t1);
printf("Number of students who failed all subjects: %lld\n", t0);
}
int main(){
while(1){
welcome();
scanf("%lld", &op);
switch(op){
case 0: return 0;
case 1: Add(); break;
case 2: Remove(); break;
case 3: Query(); break;
case 4: Show_ranking(); break;
case 5: Show_Statistics(); break;
}
}
return 0;
}