求助!uDebug已过,但是UVA还是WA
查看原帖
求助!uDebug已过,但是UVA还是WA
453501
cqsyn楼主2022/8/24 07:09

uDebug 和样例已经过了,但是交上去WA哎。

#include<bits/stdc++.h>
#define eps 1e-5
using namespace std;
struct students{
	string SID,CID,name;//学生个人ID,班级ID,名字 
	int score[4];//语,数,英,编程
}p[105];
int lp;
string sub[4]={"Chinese","Mathematics","English","Programming"};
set<string> allSID;

void Add(){
	string SID;
	while(cin>>SID,SID.size()!=1||SID[0]!='0'){
		printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n");
		string CID,name;
		int score[4];
		cin>>CID>>name>>score[0]>>score[1]>>score[2]>>score[3];
		if(allSID.count(SID)){printf("Duplicated SID.\n");continue;}
		allSID.insert(SID);
		p[++lp]=(students){SID,CID,name,score[0],score[1],score[2],score[3]};
	}
	printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n");
}

void Remove(){
	string SIDorname;
	while(cin>>SIDorname,SIDorname.size()!=1||SIDorname[0]!='0'){
		printf("Please enter SID or name. Enter 0 to finish.\n");
		int cnt=0;
		if('0'<=SIDorname[0]&&SIDorname[0]<='9'){
			string SID=SIDorname;
			for(int i=1;i<=lp;i++)if(SID==p[i].SID){
				allSID.erase(SID);
				for(int j=i;j<=lp;j++)p[j]=p[j+1];
				--lp,cnt++;
				break;
			}
		}else{
			string name=SIDorname;
			for(int i=1;i<=lp;i++)if(name==p[i].name){
				allSID.erase(p[i].SID);
				for(int j=i;j<=lp;j++)p[j]=p[j+1];
				--lp,cnt++,i--;
			}
		}
		printf("%d student(s) removed.\n",cnt);
	}
	printf("Please enter SID or name. Enter 0 to finish.\n");
}

void Query(){
	string SIDname;
	while(cin>>SIDname,SIDname.size()!=1||SIDname[0]!='0'){
		printf("Please enter SID or name. Enter 0 to finish.\n");
		int cnt=0;
		if('0'<=SIDname[0]&&SIDname[0]<='9'){
			string SID=SIDname;
			for(int i=1;i<=lp;i++)if(SID==p[i].SID){
				for(int j=1;j<=lp;j++)if(i!=j&&p[j].score[0]+p[j].score[1]+p[j].score[2]+p[j].score[3]>p[i].score[0]+p[i].score[1]+p[i].score[2]+p[i].score[3])cnt++;
				printf("%d ",cnt+1);
				cout<<p[i].SID<<" "<<p[i].CID<<" "<<p[i].name<<" ";
				printf("%d %d %d %d %d %.2f\n",p[i].score[0],p[i].score[1],p[i].score[2],p[i].score[3],p[i].score[0]+p[i].score[1]+p[i].score[2]+p[i].score[3],(p[i].score[0]+p[i].score[1]+p[i].score[2]+p[i].score[3])/4.0+eps);
				break;
			}
		}else{
			string name=SIDname;
			for(int i=1;i<=lp;i++)if(name==p[i].name){
				cnt=0;
				for(int j=1;j<=lp;j++)if(i!=j&&p[j].score[0]+p[j].score[1]+p[j].score[2]+p[j].score[3]>p[i].score[0]+p[i].score[1]+p[i].score[2]+p[i].score[3])cnt++;
				printf("%d ",cnt+1);
				cout<<p[i].SID<<" "<<p[i].CID<<" "<<p[i].name<<" ";
				printf("%d %d %d %d %d %.2f\n",p[i].score[0],p[i].score[1],p[i].score[2],p[i].score[3],p[i].score[0]+p[i].score[1]+p[i].score[2]+p[i].score[3],(p[i].score[0]+p[i].score[1]+p[i].score[2]+p[i].score[3])/4.0+eps);
			}
		}
	}
	printf("Please enter SID or name. Enter 0 to finish.\n");
}

void ranking(){
	printf("Showing the ranklist hurts students' self-esteem. Don't do that.\n");
	return;
}

void Statistics(){
	printf("Please enter class ID, 0 for the whole statistics.\n");
	string CID;
	cin>>CID;
	if(CID[0]=='0'){
		int pass[4]={0,0,0,0},fail[4]={0,0,0,0};
		double Average[4]={0,0,0,0};
		for(int i=1;i<=lp;i++){if(p[i].score[0]>=60) pass[0]++;else fail[0]++;Average[0]+=p[i].score[0];}
		for(int i=1;i<=lp;i++){if(p[i].score[1]>=60) pass[1]++;else fail[1]++;Average[1]+=p[i].score[1];}
		for(int i=1;i<=lp;i++){if(p[i].score[2]>=60) pass[2]++;else fail[2]++;Average[2]+=p[i].score[2];}
		for(int i=1;i<=lp;i++){if(p[i].score[3]>=60) pass[3]++;else fail[3]++;Average[3]+=p[i].score[3];}
		for(int i=0;i<4;i++){
			Average[i]=Average[i]/lp;
			cout<<sub[i]<<endl;
			printf("Average Score: %.2lf\nNumber of passed students: %d\nNumber of failed students: %d\n\n",Average[i]+eps,pass[i],fail[i]);
		}
		int ALL=0,p3=0,p2=0,p1=0,failALL=0;
		for(int i=1;i<=lp;i++){
			int num=0;
			for(int j=0;j<4;j++)if(p[i].score[j]>=60)num++;
			if(num==4)ALL++;
			else if(num==3)p3++;
			else if(num==2)p2++;
			else if(num==1)p1++;
			else if(num==0)failALL++;
		}
		printf("Overall:\nNumber of students who passed all subjects: %d\nNumber of students who passed 3 or more subjects: %d\nNumber of students who passed 2 or more subjects: %d\nNumber of students who passed 1 or more subjects: %d\nNumber of students who failed all subjects: %d\n\n",ALL,ALL+p3,ALL+p3+p2,ALL+p3+p2+p1,failALL);		
	}else{
		int pass[4]={0,0,0,0},fail[4]={0,0,0,0},k=0;
		double Average[4]={0,0,0,0};
		for(int i=1;i<=lp;i++){if(p[i].score[0]>=60&&p[i].CID==CID) pass[0]++;else if(p[i].CID==CID)fail[0]++;if(p[i].CID==CID)Average[0]+=p[i].score[0];}
		for(int i=1;i<=lp;i++){if(p[i].score[1]>=60&&p[i].CID==CID) pass[1]++;else if(p[i].CID==CID)fail[1]++;if(p[i].CID==CID)Average[1]+=p[i].score[1];}
		for(int i=1;i<=lp;i++){if(p[i].score[2]>=60&&p[i].CID==CID) pass[2]++;else if(p[i].CID==CID)fail[2]++;if(p[i].CID==CID)Average[2]+=p[i].score[2];}
		for(int i=1;i<=lp;i++){if(p[i].score[3]>=60&&p[i].CID==CID) pass[3]++;else if(p[i].CID==CID)fail[3]++;if(p[i].CID==CID)Average[3]+=p[i].score[3];}
		for(int i=1;i<=lp;i++)if(p[i].CID==CID)k++;
		for(int i=0;i<4;i++){
			Average[i]=Average[i]/k;
			cout<<sub[i]<<endl;
			printf("Average Score: %.2lf\nNumber of passed students: %d\nNumber of failed students: %d\n\n",Average[i]+eps,pass[i],fail[i]);
		}
		int ALL=0,p3=0,p2=0,p1=0,failALL=0;
		for(int i=1;i<=lp;i++)if(p[i].CID==CID){
			int num=0;
			for(int j=0;j<4;j++)if(p[i].score[j]>=60)num++;
			if(num==4)ALL++;
			else if(num==3)p3++;
			else if(num==2)p2++;
			else if(num==1)p1++;
			else if(num==0)failALL++;
		}
		printf("Overall:\nNumber of students who passed all subjects: %d\nNumber of students who passed 3 or more subjects: %d\nNumber of students who passed 2 or more subjects: %d\nNumber of students who passed 1 or more subjects: %d\nNumber of students who failed all subjects: %d\n\n",ALL,ALL+p3,ALL+p3+p2,ALL+p3+p2+p1,failALL);
	}
}

int main(){
	freopen("out.txt","w",stdout);
	while(1){
		printf("Welcome to Student Performance Management System (SPMS).\n\n1 - Add\n2 - Remove\n3 - Query\n4 - Show ranking\n5 - Show Statistics\n0 - Exit\n\n");		
		int op;scanf("%d",&op);
		switch(op){
			case 1:
				Add();
				break;
			case 2:
				Remove();
				break;
			case 3:
				Query();
				break;
			case 4:
				ranking();
				break;
			case 5:
				Statistics();
				break;
			case 0:
				return 0;
			default:
				//没有什么N用
				break;
		}
	}
	return 0;
}

2022/8/24 07:09
加载中...