学习内容
1.高数齐次方程
2.牛客STL题
链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
题目描述
给你一个1->n的排列和一个栈,入栈顺序给定
你要在不打乱入栈顺序的情况下,对数组进行从大到小排序
当无法完全排序时,请输出字典序最大的出栈序列
输入描述:
第一行一个数n 第二行n个数,表示入栈的顺序,用空格隔开,结尾无空格
输出描述:
输出一行n个数表示答案,用空格隔开,结尾无空格
示例1
输入
5
2 1 5 3 4
输出
5 4 3 1 2
说明
2入栈;1入栈;5入栈;5出栈;3入栈;4入栈;4出栈;3出栈;1出栈;2出栈
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
stack <int> st;
int main() {
int n;
cin >> n;
int a[1000001], b[1000001], i, m = n - 1, flag = 0;
for (i = 0; i < n; i++)
cin >> a[i];
for (i = n-1;i >=0;i--)
b[i] = max(a[i], b[i + 1]);//前i个数的最大值
for (i = 0; i < n; i++) {
while(st.size()&&st.top()>=b[i])
{
cout<<st.top()<<" ";
st.pop();
}
st.push(a[i]);
}
while (st.size()) {
cout <<st.top()<<" ";
st.pop();
}
return 0;
}