【PAT-A】1083. List Grades 写题记录

水题,测了下读题+写题用了8min。

#include <cstdio>
#include <cstring>
#include <algorithm> 
using namespace std;
struct student{
	char name[13];
	char ID[13];
	int grade;
}stu[100020];

bool cmp(student a,student b){
	return a.grade>b.grade;
}
int main(){
	int n;
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		scanf("%s",&stu[i].name);
		scanf("%s",&stu[i].ID);
		scanf("%d",&stu[i].grade);
	}
	int g1,g2;
	scanf("%d %d",&g1,&g2);
	sort(stu,stu+n,cmp);
	bool flag=false;
	for (int i=0;i<n;i++){
		if (stu[i].grade>=g1 && stu[i].grade<=g2) {
			printf("%s %s\n",stu[i].name,stu[i].ID);
			flag = true;
		}
	}
	if (flag == false) printf("NONE");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43456345/article/details/85323425