p99~p101:

1、迭代器的指向:容器内的元素或者尾元素的下一位。

2、迭代器与整数相加减返回值为移动了若干位置的迭代器。

3、迭代器间相加减返回值则是类型为 difference_type 的带符号整数。

4、使用迭代器运算的一个经典算法是二分搜索。

(注:字典序实际是按照ASCII来排的,具体如下:

0-9(对应数值48-59);A-Z(对应数值65-90);a-z(对应数值97-122);因此,按照从小到大排序,大写总是排在前面

#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include<vector>
using std::vector;
#include<string>
using std::string;
int main()
{
// 定义一个有序的vector<string>
vector<string> svec{"Abigal", "Baey", "Candice",
"DAISY", "EILEEN", "FREDERICA", "GINA"};
// 输入要查找的名字
string name;
cin >> name;
// 二分搜索
auto beg = svec.begin(), end = svec.end();
auto mid = svec.begin() + (end - beg)/;
while (mid != end && *mid != name) {
if (name < *mid) {
end = mid;
} else {
beg = mid + ;
}
mid = beg + (end - beg)/2;
}
if (*mid == name) {
cout << mid - svec.begin() << endl;
} else {
cout << "Not found!" << endl;
}
return ;
}

练习3.24

1

#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<vector>
using std::vector;int main()
{
int temp;
vector<int> v;
while(cin >> temp) {
v.push_back(temp);
}
// 用迭代器遍历、访问元素
for(auto it = v.cbegin();
it != v.cend() - ; ++it) {
cout << *it + *(it + ) << endl;
}
return ;
}

2

#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<vector>
using std::vector;int main()
{
int temp;
vector<int> v;
while(cin >> temp) {
v.push_back(temp);
}
// 用迭代器遍历、访问元素
auto head = v.cbegin();
auto tail = v.cend() - ;
for( ; head <= tail; ++head, --tail) {
cout << *head + *tail << endl;
}
return ;
}

练习3.25

#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<vector>
using std::vector;
int main()
{
vector<unsigned> score(, );
unsigned grade;
auto ind = score.begin();
while (cin >> grade) {
if (grade <= )
++*(ind + grade/);
}
for (auto i: score) {
cout << i << endl;
}
return ;
}

练习3.26

迭代器间不支持加法运算。(参考99页)

c++第十六天的更多相关文章

  1. javaSE第二十六天

    第二十六天    414 1:网络编程(理解)    414 (1)网络编程:用Java语言实现计算机间数据的信息传递和资源共享    414 (2)网络编程模型    414 (3)网络编程的三要素 ...

  2. javaSE第十六天

    第十六天    140 1:List的子类(掌握)    140 (1)List的子类特点    140 (2)ArrayList    141 A:没有特有功能需要学习    141 B:案例    ...

  3. 第三百五十六天 how can I 坚持

    一年了,三百五十六天.写个算法算下对不对. 今天突然想买辆自行车了.云马智行车,还是捷安特,好想买一辆. 网好卡.貌似少记了一天呢,357了.好快. 睡觉了,还没锻炼呢,太晚了. 1458748800 ...

  4. IT第二十六天 - Swing、上周总结

    IT第二十六天 上午 Swing 1.对于方法的参数如果是int数值类型,应该直接调用该类中的常量属性,而不应该直接填入数字 2.Toolkit类中定义的方法是可以直接访问本地计算机(操作系统)信息的 ...

  5. Python第二十六天 python装饰器

    Python第二十六天 python装饰器 装饰器Python 2.4 开始提供了装饰器( decorator ),装饰器作为修改函数的一种便捷方式,为工程师编写程序提供了便利性和灵活性装饰器本质上就 ...

  6. OCM_第十六天课程:Section7 —》GI 及 ASM 安装配置 _安装 GRID 软件/创建和管理 ASM 磁盘组/创建和管理 ASM 实例

    注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...

  7. 孤荷凌寒自学python第八十六天对selenium模块进行较详细的了解

    孤荷凌寒自学python第八十六天对selenium模块进行较详细的了解 (今天由于文中所阐述的原因没有进行屏幕录屏,见谅) 为了能够使用selenium模块进行真正的操作,今天主要大范围搜索资料进行 ...

  8. 孤荷凌寒自学python第七十六天开始写Python的第一个爬虫6

    孤荷凌寒自学python第七十六天开始写Python的第一个爬虫6 (完整学习过程屏幕记录视频地址在文末) 今天在上一天的基础上继续完成对我的第一个代码程序的书写. 不过由于对python-docx模 ...

  9. 孤荷凌寒自学python第六十六天学习mongoDB的基本操作并进行简单封装5

    孤荷凌寒自学python第六十六天学习mongoDB的基本操作并进行简单封装5并学习权限设置 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第十二天. 今天继续学习mongo ...

  10. 孤荷凌寒自学python第五十六天通过compass客户端和mongodb shell 命令来连接远端MongoDb数据库

    孤荷凌寒自学python第五十六天通过compass客户端和mongodb shell 命令来连接远端MongoDb数据库 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第二 ...

随机推荐

  1. vue报错 Module not found: Error: Cannot resolve 'file' or 'directory'

    炸了,我好写sell而组件,直接就用了,我的天哪 看你的写了吗,就用: Module not found: Error: Cannot resolve 'file' or 'directory' 页另 ...

  2. MongoDB 学习笔记2----条件操作符

    条件操作符:用于两个比较两个表达式并从mongdb中获取文档 mongodb常见的操作符及解析说明 $lt:小于 example:ago<20 $lte:小于等于 example:<=20 ...

  3. HDU 1166 - 敌兵布阵 - [单点修改、区间查询zkw线段树]

    题还是那个题:http://www.cnblogs.com/dilthey/p/6827959.html 不过我们今天换一种线段树实现来做这道题: 关于zkw线段树的讲解:https://zhuanl ...

  4. HDU 2602 - Bone Collector - [01背包模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...

  5. AIX 7命令行weblogic建域流水

    $ ./config.shUnable to instantiate GUI, defaulting to console mode. <------------------- Fusion M ...

  6. html 复制 有时不显示样式

    是因为有中文的空格 /**HTML**/ div.ani /**css**/ .ani{ width:480px; height:320px; margin:50px auto; overflow:  ...

  7. 通过 Kubernetes 和容器实现 DevOps

    https://mp.weixin.qq.com/s/1WmwisSGrVyXixgCYzMA1w 直到 Docker 的出现(2008 年),容器才真正具备了较好的可操作性和实用性.容器技术的概念最 ...

  8. JMeter(十四)-自动生成测试报告

    很多朋友都在问jmeter如何生成测试报告,这里随便说两句. 环境要求 1:jmeter3.0版本之后开始支持动态生成测试报表 2:jdk版本1.7以上 3:需要jmx脚本文件 基本操作 1:在你的脚 ...

  9. python修饰器各种实用方法

    This page is meant to be a central repository of decorator code pieces, whether useful or not <wi ...

  10. easyUi引入方法

    1:创建一个动态web工程:    去官网http://www.jeasyui.net/download/下载官网文档    我去官网下载的最新版本,个人根据自己的需求下载即可.2:在webConte ...