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

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

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

#include <functional>
#include <iostream>
#include <iterator>
#include <vector>
#include<algorithm>
using namespace std;

int main() {
    int a;
    vector<int>v;
    while (cin >> a) { // 注意 while 处理多个 case
        v.push_back(a);
    }
    v.erase(v.begin());
    int flag=v[v.size()-1];
    v.pop_back();
    if(flag==0)
    {
        sort(v.begin(),v.end());
    }
    else{
        sort(v.begin(),v.end(),std::greater<int>());
    }
    for(auto c: v)
    {
        cout<<c<<" ";
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

01-11 08:47
门头沟学院 Java
程序员花海_:所以看起来还是实习的好处多 给导师打黑工能学到什么
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务