题解 | #使用算法#

使用算法

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

注意事项:头文件# 1、排序算法sort(v.begin(),v.end(),fun) fun表示排序的方式,升序还是逆序,需要自己构造返回值为bool的函数 2、遍历算法for_each(v.begin(),v.end(),fun) fun表示遍历的方式,输出值还是其他,需要自己构造函数 3、其他STL算法也需掌握

#include <vector>
// write your code here......
#include<algorithm>
using namespace std;
void Show(int num)
{
    cout<<num<<" ";
}
bool Compare(int a,int b)
{
    return a>b;
}

int main() {

    int num;
    vector<int> v;
    for (int i = 0; i < 5; i++) {
        cin >> num;
        v.push_back(num);
    }

    // write your code here......
    sort(v.begin(),v.end(),Compare);
    for_each(v.begin(),v.end(),Show);
    return 0;
}
全部评论

相关推荐

11-04 19:05
已编辑
东莞城市学院 单片机
不知道怎么取名字_:你这个要实习两年?哪有这么久的,感觉就是即使你毕业了,但还按实习的话,是不是不用给你缴社保公积金啥的
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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