题解 | #明明的随机数#

明明的随机数

http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0

#include <iostream>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

int main(){
    int N = 0;
    cin>>N;
    
    priority_queue<int> pq;
    
    for(int i = 0; i < N; i++){
        int num = 0;
        cin>>num;
        pq.push(num);
    }
    
    stack<int> st;
    st.push(pq.top());
    pq.pop();
    while(!pq.empty()){
        if(st.top() != pq.top()){
            st.push(pq.top());
        }
        pq.pop();
    }
    
    vector<int> res;
    while(!st.empty()){
        res.push_back(st.top());
        st.pop();
    }
    
    for(int i = 0; i < res.size(); i++){
        cout << res[i] << endl;
    }
    
    return 0;
}
华为题库题解 文章被收录于专栏

牛客华为题库的题解

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务