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++)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-27Excel中实现拖动排序的简单教程
- 2024-11-27Rocket消息队列资料:新手入门指南
- 2024-11-27rocket消息队资料详解与入门指南
- 2024-11-27RocketMQ底层原理资料详解入门教程
- 2024-11-27RocketMQ项目开发资料:新手入门教程
- 2024-11-27RocketMQ项目开发资料详解
- 2024-11-27RocketMQ消息中间件资料入门教程
- 2024-11-27初学者指南:深入了解RocketMQ源码资料
- 2024-11-27Rocket消息队列学习入门指南
- 2024-11-26Rocket消息中间件教程:新手入门详解