题解 | #求最大最小数#
求最大最小数
https://www.nowcoder.com/practice/82e5ff335eeb486aab359767895cc7b4
#include <iostream> #include "queue" using namespace std; struct answer{ int max; int min; }; int main() { queue<answer> result;//记录结果 int n; while (scanf("%d",&n)!=EOF){ //记录输入 int temp; priority_queue<int> numbers_max; priority_queue<int> numbers_min; for (int i=0;i<n;++i){ scanf("%d",&temp); numbers_max.push(temp); numbers_min.push(-temp); } //记录结果 answer *t = new answer; t->max = numbers_max.top(); t->min = -numbers_min.top(); result.push(*t); } while (!result.empty()){ printf("%d %d\n",result.front().max,result.front().min); result.pop(); } return 0; }