1075 PAT Judge 测试点2

原题 传送门

如下测试数据:

3 1 5
10
00001 1 -1
00001 1 0
00002 1 2
00004 1 -1
00002 1 2

正确结果应该为:

1 00002 2 2
2 00001 0 0

错误结果为:

1 00002 2 2
也就是说,如果一个学生编译不通过(即,分数为-1), 不显示。而,如果一个学生本身就得了0 分, 则应该显示。

AC代码:


#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int p[6]={0};


struct student{
	int id;
	int total; //总分
	int score[5];	//各题目成绩
	bool isPrint; //是否应该打印出来
	int count;	//满分通过题目数量
	student(){
		id = 0;
		total = 0;
		score[0] = -1;	score[1] = -1;score[2] = -1;score[3] = -1;score[4] = -1;
		isPrint = 0; count = 0;
	}
}stu[10005]	;

student stu2[10005]; //用于保存排序后,需要打印的学生

bool cmp(student x, student y){
	if(x.total != y.total)  return x.total> y.total;
	else if(x.count != y.count)  return x.count>y.count;
	else return x.id<y.id;
}


int main(){
	int n,k,m;
	int id,number,grade;
	
	scanf("%d %d %d",&n,&k,&m);
	for(int i=0;i<k;i++){
		scanf("%d",&p[i]);
	}
	//	输入及预处理
	for(int i=0;i<m;i++){
		scanf("%d %d %d",&id, &number, &grade);
		if(stu[id].id !=0){
			number -- ;
			if(grade!=-1) stu[id].isPrint = 1; 
			if(grade==-1) grade = 0;
			if(stu[id].score[number] < grade && grade<=p[number] ){
				stu[id].score[number] = grade; 
			}
		}else{
			stu[id].id = id;
			if(grade!=-1) stu[id].isPrint = 1; 
			
			if(grade==-1) grade = 0;
			number -- ;
			stu[id].score[number] = grade;
		
		}
	}
	// 计算每个学生  总分 total 和 满分通过题目数量 count
	for(int i=0;i<=n;i++){
		int sum=0,count=0;
		for(int j=0;j<k;j++){
			if(stu[i].score[j] != -1)
				sum+= stu[i].score[j];
			
			if(stu[i].score[j] == p[j]) count++;
		}
		stu[i].total  = sum;
		stu[i].count = count;
	}


	sort(stu, stu+n+1, cmp);

	// 将排序后的数据,需要答应的提前 存入 stu2[]数组
	int s1=0;
	for(int i=0;i<=n;i++){
		if(stu[i].isPrint == 0) continue;
		stu2[s1++] = stu[i];
	}

	//排名处理及输出
	int r=1;
	for(int i=0;i<s1;i++){
		if(i>0 && stu2[i].total == stu2[i-1].total)
			printf("%d %05d",r,stu2[i].id);
		else{
			r=i+1;	
			printf("%d %05d",r,stu2[i].id);
		}
		
		printf(" %d",stu2[i].total);
		for(int j=0;j<k;j++){
			if(stu2[i].score[j] ==-1) printf(" -");
			else printf(" %d",stu2[i].score[j]);
		}
		printf("\n");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值