关闭

C++ algorithm partition

标签: C++算法
651人阅读 评论(0) 收藏 举报
分类:
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <iostream>

// g++ 4.9.2 -std=c++11
// function that take a string and return true
// indicating the string has five characters 
// or more
bool pred(const std::string &s)
{
        return !(s.size() < 5);
}

int main()
{
        std::vector<std::string> words;
        std::string str;
        while (std::cin >> str) {
                words.push_back(str);
        }
        std::copy(words.begin(), words.end(), std::ostream_iterator<std::string>(std::cout, " "));
        std::cout << "\n";

        auto it = std::partition(words.begin(), words.end(), pred);
        std::copy(words.begin(), it, std::ostream_iterator<std::string>(std::cout, " "));
        std::cout << "\n";

        return 0;
}

from C++ primer 5th Exercise 10.13(P.387)

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:22978次
    • 积分:501
    • 等级:
    • 排名:千里之外
    • 原创:23篇
    • 转载:24篇
    • 译文:0篇
    • 评论:0条
    文章分类