IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> C++ prime 第十章 -> 正文阅读

[C++知识库]C++ prime 第十章

10.1

#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
#include<forward_list>
#include<deque>
#include<algorithm>

using namespace std;



int main(int argc, char** argv)
{
	int a[10] = { 0,1,2,5,4,5,4,5,4,5 };
	vector<int> vec(a, a + 10);
	int value = 5;
	cout << value << "出现的次数为:" << count(vec.begin(), vec.end(), value) << endl;

	return 0;
}

10.11

#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
#include<forward_list>
#include<deque>
#include<algorithm>
#include<list>
using namespace std;

bool isShorter(const string& s1, const string& s2)
{
	return s1.size() < s2.size();


}

void elimDups(vector<string>& words)
{
	sort(words.begin(), words.end());   //按字典排序 
	auto end_unique = unique(words.begin(), words.end());  //把重复单词放置末尾  返回不重复区域之后的一个位置

	words.erase(end_unique, words.end());  // 删除重复区域

}

int main(int argc, char** argv)
{
	
	vector<string> words = { "the","quick","red","fox","jumps","over","the","slow","red","turtle" };
	elimDups(words);

	stable_sort(words.begin(), words.end(), isShorter);   //按长短排序  长度相同的单词 不打乱字典排序
	for (const auto &s : words)
	{
		cout << s << " ";
	}


	return 0;
}

10.13

#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
#include<forward_list>
#include<deque>
#include<algorithm>
#include<list>
using namespace std;

bool cmp(const string& a)
{
	return a.size() >= 5;


}


int main(int argc, char** argv)
{
	
	vector<string> words = { "the","quick","red","fox","jumps","over","the","slow","red","turtle" };

	auto par = partition(words.begin(), words.end(), cmp);

	words.erase(par, words.end());

	for (auto &i : words)
	{
		cout << i << "  ";
	}


	return 0;
}

10.18

#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
#include<forward_list>
#include<deque>
#include<algorithm>
#include<list>

using namespace std;

bool isShorter(const string& s1, const string& s2) {
	return s1.size() < s2.size();
}

void elimDups(vector<string>& words) {
	sort(words.begin(), words.end());
	auto end_unique = unique(words.begin(), words.end());
	words.erase(end_unique, words.end());
}

bool cmp(const string& a)
{
	return a.size() >= 4;

}

void biggis(vector<string>& s, vector<string>::size_type sz)
{
	elimDups(s);
	stable_sort(s.begin(), s.end(), [](const string& a, const string& b) {return a.size() < b.size(); });
	auto it = partition(s.begin(), s.end(), [sz](const string& s) {return s.size() <= sz; });
	for (it; it != s.end(); ++it)
	{
		cout << *it << "  ";
	}
}

int main(int argc, char** argv)
{
	
	vector<string> words = { "the","quick","red","fox","jumps","over","the","slow","red","turtle" };

	biggis(words, 4);

	/*auto par = partition(words.begin(), words.end(), cmp);*/

	/*words.erase(par, words.end());*/

	/*for (auto &i : words)
	{
		cout << i << "  ";
	}*/

	/*int a = 1;
	auto  f = [a](int b) {return a + b; };
	cout << f(2)  ;*/

	return 0;
}

10.25

#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
#include<forward_list>
#include<deque>
#include<algorithm>
#include<list>
#include<functional>
#include<iterator>

using namespace std;

using namespace placeholders;

//bool isShorter(const string& s1, const string& s2) {
//	return s1.size() < s2.size();
//}

vector<string> elimDups(vector<string>& words) {
	sort(words.begin(), words.end());
	auto end_unique = unique(words.begin(), words.end());
	words.erase(end_unique, words.end());
	return words;
}
//
//bool cmp(const string& a)
//{
//	return a.size() >= 4;
//
//}
//
//void biggis(vector<string>& s, vector<string>::size_type sz)
//{
//	elimDups(s);
//	stable_sort(s.begin(), s.end(), [](const string& a, const string& b) {return a.size() < b.size(); });
//	auto it = partition(s.begin(), s.end(), [sz](const string& a, const string& b) {return a.size() < b.size(); });
//
//}
//bool judge_size(string& s, string::size_type sz)
//{
//	return s.size() <= sz;
//}

bool check_size(string& s , string::size_type sz)
{
	return  s.size() >= sz;
}
int main(int argc, char** argv)
{
	
	vector<string> vs = { "the","quick","red","fox","jumps","over","the","slow","red","turtle" };
	list<string> lis;
	auto iter = partition(vs.begin(), vs.end(), bind(check_size, _1, 5));
	for (const auto s : vs)
		cout << s << " ";
	cout << endl;

	vs.erase(iter, vs.end());
	for (const auto s : vs)
		cout << s << " ";
	cout << endl;
	system("pause");
	return 0;

	
}

10.27

#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
#include<forward_list>
#include<deque>
#include<algorithm>
#include<list>
#include<functional>
#include<iterator>

using namespace std;

using namespace placeholders;

//bool isShorter(const string& s1, const string& s2) {
//	return s1.size() < s2.size();
//}

vector<string> elimDups(vector<string>& words) {
	sort(words.begin(), words.end());
	auto end_unique = unique(words.begin(), words.end());
	words.erase(end_unique, words.end());
	return words;
}
//
//bool cmp(const string& a)
//{
//	return a.size() >= 4;
//
//}
//
//void biggis(vector<string>& s, vector<string>::size_type sz)
//{
//	elimDups(s);
//	stable_sort(s.begin(), s.end(), [](const string& a, const string& b) {return a.size() < b.size(); });
//	auto it = partition(s.begin(), s.end(), [sz](const string& a, const string& b) {return a.size() < b.size(); });
//
//}
//bool judge_size(string& s, string::size_type sz)
//{
//	return s.size() <= sz;
//}

bool check_size(string& s , string::size_type sz)
{
	return  s.size() >= sz;
}
int main(int argc, char** argv)
{
	
	string a[10] = { "love","love8","love","love","love","h","diuw","diuwudhg257","love","d" };
	vector<string> vec1(a, a + 10);//利用数组初始化vector  
	vector<string> vec2;
	//实现包含头文件iterator
	unique_copy(vec1.cbegin(), vec1.cend(), back_inserter(vec2));//不支持push_front?

	cout << "字符串中的不重复字符为:";
	for (int i = 0; i < vec2.size(); ++i)
	{
		cout << vec2[i] << " ";
	}


	system("pause");
	return 0;

	
}

10.29

#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
#include<forward_list>
#include<deque>
#include<algorithm>
#include<list>
#include<functional>
#include<iterator>

using namespace std;

using namespace placeholders;


int main(int argc, char** argv)
{
	
	vector<string> str;
	istream_iterator<string> str_read(cin), eof;

	copy(str_read, eof, back_inserter(str));

	for (auto it : str)
	{
		cout << it << " ";
	}
	system("pause");
	return 0;

	
}

10.37

#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<vector>
#include<forward_list>
#include<deque>
#include<algorithm>
#include<list>
#include<functional>
#include<iterator>

using namespace std;

using namespace placeholders;


int main(int argc, char** argv)
{
	/*istream_iterator<int> in_iter(cin), eof;
	ostream_iterator<int> out_iter(cout);*/

	int a[10] = { 1,0,3,0,4,5,8,9,6,5 };
	vector<int> vec1(a, a + 10);
	list<int> list1;
	copy(vec1.rbegin() + 2, vec1.rend() - 3, back_inserter(list1));
	
	
	for (auto it = list1.begin(); it != list1.end(); ++it)

	{
		cout << *it << " ";
	}
	

	return 0;
	
}

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2021-10-29 12:49:03  更:2021-10-29 12:51:38 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 5:04:10-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码