C++primer 练习10.16
// 10.3.2.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std; string & make_plural(int cnt, string &str)
{
str=cnt > ? (str + "s") : str;
return str;
} void biggies(vector<string> &words, vector<string>::size_type sz)
{
sort(words.begin(), words.end());
//按照默认形式对容器中的元素排序 auto uniqIte = unique(words.begin(), words.end());
//将重复的元素放到迭代器范围的后面,并且返回第一个重复元素的迭代器 words.erase(uniqIte,words.end());
//删除重复的元素
//stable_sort(words.begin(), words.end(), [](const string &s1, const string &s2) {return s1.size() < s2.size();});
//这个是书上的写法 auto ite=partition(words.begin(), words.end(), [sz](const string &s) {return s.size() >= sz;});
//返回第一个迭代器范围内不满足lambda表达式的元素,并且将满足表达式的元素放在范围前面,不满足的放在后面
unsigned int cnt = ;
for (auto beg = words.begin();beg != ite;++beg, ++cnt);
//得到长度不小于sz的字符串的个数 cout << cnt << " " << make_plural(cnt, string("word")) << " of length " <<
sz << " or longer" << endl; for_each(words.begin(), ite, [](const string &s) {cout << s << " ";});
//输出迭代器范围内的元素(即长度不小于sz的元素)
cout << endl;
} int main()
{
vector<string> strVec = { "lidanda","hahaha","liyou","wumei","ni","sansan" };
biggies(strVec, );
return ;
}
C++primer 练习10.16的更多相关文章
- 背水一战 Windows 10 (16) - 动画: ThemeAnimation(主题动画)
[源码下载] 背水一战 Windows 10 (16) - 动画: ThemeAnimation(主题动画) 作者:webabcd 介绍背水一战 Windows 10 之 动画 PopInThemeA ...
- ERROR 2003 (HY000): Can't connect to MySQL server on '10.16.115.101' (111)
ubuntu安装之后mysql,使用apt-get安装命令,默认为同意只本地访问 root@idata1:~/software# mysql -uroot -p123456 -h10.16.115.1 ...
- 10.16 NOIP模拟赛
目录 2018.10.16 NOIP模拟赛 A 购物shop B 期望exp(DP 期望 按位计算) C 魔法迷宫maze(状压 暴力) 考试代码 C 2018.10.16 NOIP模拟赛 时间:2h ...
- ERROR: openstack Error finding address for http://10.16.37.215:9292/v1/images: [Errno 32] Broken pipe
Try to set: no_proxy=10.16.37.215 this should help 转自: http://askubuntu.com/questions/575938/error-i ...
- 2019.10.16&17小结
话说也蛮久没写小结了,主要这两次考试失分严重,还是总结下吧. 10.16 T1 小奇挖矿2 100/0 [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿石交易市 ...
- [NOIP2018模拟赛10.16]手残报告
[NOIP2018模拟赛10.16]手残报告 闲扯 炉石乱斗模式美滋滋啊,又颓到好晚... 上来T2先敲了树剖,看T1发现是个思博DP,然后没过大样例,写个暴力发现还是没过大样例!?才发现理解错题意了 ...
- windows10 下访问 virtualbox 虚拟机的linux15.10/16.04 系统 及 用 putty 访问虚拟机的配置
参考: http://www.doc88.com/p-915707596190.html --- 安装samba http://my.oschina.net/u/2260265/blog/405598 ...
- java 2 8 10 16
An integer literal may be expressed in decimal (base 10), hexadecimal (base 16), octal (base 8), or ...
- 《C++ Primer Plus》16.3 标准模板库 学习笔记
STL提供了一组表示容器.迭代其.函数对象和算法的模板.容器是一个与数组类似的单元,可以存储若干个值.STL容器是同质的,即存储的值的类型相同:算法是完成特定任务(如对数组进行排序或在链表中查找特定值 ...
随机推荐
- 百度ue富文本编辑器setContent方法报错初始化加载内容失败解决办法
解决方案: 不能创建editor之后马上使用ueditor.setContent('文本内容');要等到创建完成之后才可以使用 ueditor.addListener("ready" ...
- C#-提取网页中的超链接
转载:http://www.wzsky.net/html/Program/net/26849.htmlusing System; using System.Xml; using System.Text ...
- 自媒体时代网络脱口秀节目的“五W”分析——以《罗辑思维》为例
摘 要:随着互联网的发展,网络媒介生态的变化正在悄然进行.一大批网络自媒体节目<罗辑思维><晓说><凯子曰>等进入大众视线,成为大众关注的新焦点,其中<罗辑思 ...
- centos 6安装redis 2.8.19
下载安装: wget https://github.com/antirez/redis/archive/2.8.19.tar.gz tar xvzf redis-stable.tar.gz cd re ...
- 异机恢复 RMAN-06023: no backup or copy of datafile 17 found to restore
前不久因工作需要使用RMAN异机恢复,很基础也很具有代表性和普遍性,希望对需要的人有所帮助. 具体过程如下: 先拷贝原库的口令文件和参数文件到备库. 然后使用如下脚本对原库进行备份: run { al ...
- 程序员书单_java web编程篇
李兴华JavaWeb开发实战经典 http://download.csdn.net/detail/shenzhq1980/9137653 Servlet与JSP核心编程 第2版_1 http://do ...
- Jquery中的offset()和position()
今天遇到这个偏移量的问题,特做此记录.以便日后查看. 先看看这两个方法的定义. offset(): 获取匹配元素在当前视口的相对偏移. 返回的对象包含两个整形属性:top 和 left.此方法只对可见 ...
- POJ #1141 - Brackets Sequence - TODO: POJ website issue
A bottom-up DP. To be honest, it is not easy to relate DP to this problem. Maybe, all "most&quo ...
- SSH_框架整合3-删除
一.普通删除 1 完善src中 类: (1)EmployeeDao.java中: //2 删除 public void delete(Integer id){ String hql="DEL ...
- 【转】JVM 分代GC策略分析
我们以Sun HotSpot VM来进行分析,首先应该知道,如果我们没有指定任何GC策略的时候,JVM默认使用的GC策略.Java虚拟机是按照分代的方式来回收垃圾空间,我们应该知道,垃圾回收主要是针对 ...