[C++ primer] ff

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/isunbin/article/details/89160958

文章目录

他## 谷歌

那你

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <list>
using namespace std;

template <typename Sequence>
inline ostream& println(Sequence const& seq)
{
    for (auto const& elem : seq)
        cout << elem << " ";
    cout << endl;
    return cout;
}

inline bool is_shorter(std::string const& lhs, std::string const& rhs)
{
    return  lhs.size() < rhs.size();
}

void elimdups(vector<string> &vs)
{
    sort(vs.begin(), vs.end());
    auto new_end = unique(vs.begin(), vs.end());
    vs.erase(new_end, vs.end());
}

int main()
{
    vector<string> v{ "1234", "1234", "1234", "Hi", "alan", "wang" };
    elimdups(v);
    stable_sort(v.begin(), v.end(), is_shorter);
    cout << "ex10.11 :\n";
    println(v);
    system("pause");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/isunbin/article/details/89160958
ff