PAT甲级 1036(C++)

2021/10/14 20:16:50

本文主要是介绍PAT甲级 1036(C++),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct stu {
	string name, id;
	char s; int grade;
};
int N; vector<struct stu>info;
bool compare(struct stu s1, struct stu s2) {
	if (s1.s != s2.s) return s1.s<s2.s;
	else return s1.grade > s2.grade;
}
int main() {
	 cin >> N;
	 if (N == 0) {
		 cout << "Absent" << endl << "Absent" << endl << "NA";
		 return 0;
	 }
	 info.resize(N);
	 for (int i = 0; i < N; i++) {
		 cin >> info[i].name >> info[i].s >> info[i].id >> info[i].grade;
	 }
	 sort(info.begin(), info.end(), compare);
	 int flag[2] = { 0 }; 
	 if (info[0].s == 'F') flag[0] = 1;
	 if (info[N - 1].s == 'M') flag[1] = 1;
	 for (int i = 0; i < 2; i++) {
		 if (flag[i] == 0)
			 cout << "Absent" << endl;
		 else {
			 int index = (i == 0) ? 0 : N - 1;
			 cout << info[index].name << " " << info[index].id << endl;
		 }	 
	 }
	 if (flag[0] == 1 && flag[1] == 1) {
		 cout << info[0].grade - info[N - 1].grade;
	 }
	 else cout << "NA";
	 return 0;
}



这篇关于PAT甲级 1036(C++)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程