zoukankan      html  css  js  c++  java
  • 函数 sort,unique,stable_sort,count_if,谓词

    bool isShorter(const string &s1,const string &s2)
    {
        return s1.size() < s2.size();                              
    }
    
    bool GT6(const string &s)
    {
        return s.size() >= 6;
    }
    
    int main()
    {
        vector<string> words;
        string nect_word;
        while (cin >> next_word){
            words.push_back(next_word);
      }    
        sort (words.begin(), words.end());
        vector<string>::iterator end_unique = unique(words.begin(), words.end());
        words.erase(end_unique, words.end());
        stable_sort(words.begin(),word.end(),isShorter);
        vector<string>::size_type wc = count_if (words.begin(), words.end(), GT6);
        cout << wc << " " << make_plural (wc, "word", "s") << " 6 characters or longer " << endl;
        return 0;
    }
        

    sort函数:将容器中元素按字典排列;

    unique函数:删除相邻的重复元素,然后重新排列输入范围内的元素,并且返回一个迭代器,表示无重复的值范围的结束;

    谓词:做某些检测的函数,返回用于条件判断的类型,指出条件是否成立;

    stable_sort函数:保留相等元素的原始相对位置,本程序里,对于相同长度的元素,将保留其字典顺序;

    count_if函数:返回使谓词函数返回条件成立的元素的个数。

  • 相关阅读:
    python day01
    Mac上安装pexpect
    raid
    SSL证书制作
    linux grep命令详解
    第一轮迭代小组成员分数分配
    M1事后分析报告(Postmortem Report)
    软件发布说明
    测试报告
    week 9 scenario testing
  • 原文地址:https://www.cnblogs.com/qiushuixiaozhanshi/p/5630042.html
Copyright © 2011-2022 走看看