题解 | #输入整型数组和排序标识,对其元素按照升序或降序进行排序#

输入整型数组和排序标识,对其元素按照升序或降序进行排序

http://www.nowcoder.com/practice/dd0c6b26c9e541f5b935047ff4156309

排序mark一下
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int n;
    while(cin>>n){
        vector<int> v;
        for(int i = 0;i<n;i++){
            int temp;
            cin>>temp;
            v.push_back(temp);
        }
        int dscd;
        cin>>dscd;
        if(dscd)sort(v.begin(),v.end(),greater<int>());
        else sort(v.begin(),v.end());
        for(auto it = v.begin();it!=v.end();it++){
            cout<<(*it)<<' ';
        }
        cout<<endl;
    }
}
全部评论

相关推荐

收到了北京经纬恒润AE产品测试部门的offer,有了解的友友吗?工作内容怎么样?加班真的很严重吗?值得去吗?
La_place:有人说的人在那边,就是正常互联网作息吧,一天十个小时出头,双休这样。加班有,但是可能也不算严重?
点赞 评论 收藏
转发
头像
05-22 20:17
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务