A1083 List Grades (25 分)
Given a list of N student records with name,ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order,and output those student records of which the grades are in a given interval. Input Specification: N Output Specification: Sample Input 1: 开始技术总结:
#define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 50; struct Student { char ID[11]; char name[11]; int grade; }student[MAXN]; bool cmp(Student a,Student b) { if (a.grade != b.grade) return a.grade > b.grade; } int main(){ int grade1,grade2; int N; scanf("%d",&N); for (int i = 0; i < N; i++) { scanf("%s%s%d",student[i].name,student[i].ID,&student[i].grade); } scanf("%d%d",&grade1,&grade2); sort(student,student + N,cmp); int flag = 0;//用来标记是否又符合条件的同学,0表示没有 for (int j = 0; j < N; j++) { if (student[j].grade <= grade2 && student[j].grade >= grade1) { printf("%s %sn",student[j].name,student[j].ID); flag = 1; } } if (flag == 0) { printf("NONE"); } system("pause"); return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |