如果题目要求你读入若干个连续整数,其间用空格隔开,换行符作为输入结束标准,数目不知道,要求你将输入的数排序打印,求max,min,排序等
用优先队列实现排序,当然使用set也可以
#include <iostream>
#include <queue>
using namespace std;
int main()
{
priority_queue<int,vector<int>,greater<int>>q;//优先队列 默认递减priority_queue<int>q
int a;
while (1) {
cin >> a;
q.push(a);
if (getchar() == '\n')//换行退出循环
break;
}
cout << "max: " << q.top()<<endl;
cout << "length: " << q.size()<<endl;
cout << "输入的数据排序后为:";
while(!q.empty()) {
cout << q.top() << " ";
q.pop();
}
return 0;
}