现在的位置: 首页 > 综合 > 正文

C++学习10

2017年06月01日 ⁄ 综合 ⁄ 共 3903字 ⁄ 字号 评论关闭

C++头文件

Name

名字

Header

头文件

Name

名字

Header

头文件

abort

<cstdlib>

ios_base

<ios_base>

accumulate

<numeric>

isalpha

<cctype>

allocator

<memory>

islower

<cctype>

auto_ptr

<memory>

ispunct

<cctype>

back_inserter

<iterator>

isspace

<cctype>

bad_alloc

<new>

istream

<iostream>

bad_cast

<typeinfo>

istream_iterator

<iterator>

bind2nd

<functional>

istringstream

<sstream>

bitset

<bitset>

isupper

<cctype>

boolalpha

<iostream>

left

<iostream>

cerr

<iostream>

less_equal

<functional>

cin

<iostream>

list

<list>

copy

<algorithm>

logic_error

<stdexcept>

count

<algorithm>

lower_bound

<algorithm>

count_if

<algorithm>

make_pair

<utility>

cout

<iostream>

map

<map>

dec

<iostream>

max

<algorithm>

deque

<deque>

min

<algorithm>

endl

<iostream>

multimap

<map>

ends

<iostream>

multiset

<set>

equal_range

<algorithm>

negate

<functional>

exception

<exception>

noboolalpha

<iostream>

fill

<algorithm>

noshowbase

<iostream>

fill_n

<algorithm>

noshowpoint

<iostream>

find

<algorithm>

noskipws

<iostream>

find_end

<algorithm>

not1

<functional>

find_first_of

<algorithm>

nounitbuf

<iostream>

fixed

<iostream>

nouppercase

<iostream>

flush

<iostream>

nth_element

<algorithm>

for_each

<algorithm>

oct

<iostream>

front_inserter

<iterator>

of stream

<fstream>

fstream

<fstream>

ostream

<iostream>

getline

<string>

ostream_iterator

<iterator>

hex

<iostream>

ostringstream

<sstream>

ifstream

<fstream>

out_of_range

<stdexcept>

inner_product

<numeric>

pair

<utility>

inserter

<iterator>

partial_sort

<algorithm>

internal

<iostream>

plus

<functional>

priority_queue

<queue>

sqrt

<cmath>

ptrdiff_t

<cstddef>

stable_sort

<algorithm>

queue

<queue>

stack

<stack>

range_error

<stdexcept>

strcmp

<cstring>

replace

<algorithm>

strcpy

<cstring>

replace_copy

<algorithm>

string

<string>

reverse_iterator

<iterator>

stringstream

<sstream>

right

<iostream>

strlen

<cstring>

runtime_error

<stdexcept>

strncpy

<cstring>

scientific

<iostream>

terminate

<exception>

set

<set>

tolower

<cctype>

set_difference

<algorithm>

toupper

<cctype>

set_intersection

<algorithm>

type_info

<typeinfo>

set_union

<algorithm>

unexpected

<exception>

setfill

<iomanip>

uninitialized_copy

<memory>

setprecision

<iomanip>

unitbuf

<iostream>

setw

<iomanip>

unique

<algorithm>

showbase

<iostream>

unique_copy

<algorithm>

showpoint

<iostream>

upper_bound

<algorithm>

size_t

<cstddef>

uppercase

<iostream>

skipws

<iostream>

vector

<vector>

sort

<algorithm>

 

 

泛型算法

find(beg,end,value);//返回指向value的迭代器(若存在);否则返回end();头文件<algorithm>

accumulate(beg,end,value);//将容器中从beg到end中的值累加到value;返回value同样的类型,头文件<numeric>;;只读算法;;

find_first_of(beg,end,beg2,end2);//在第一段范围内查找与第二段中任意元素匹配的元素,然后返回指向第一个匹配的元素。如果找不到返回end,头文件<algorithm>

fill(beg,end,value);//将容器中从beg到end的左右元素替换为value;返回值void;头文件<algorithm>

fill_n(beg,subnum,value);//将容器中从beg开始的前subnum个元素用value替代;返回值viod;头文件<algorithm>

back_inserter(容器&);//向容器中插入一个元素;返回一个绑定在该容器的插入迭代器。fill_n(back_inserter(vec),10,0);相当于在vec上调用push_back,在vec末尾添加10个0;

copy(beg,end,iter);//例如copy(lst.begin(),lst.end(),back_inserter(vec));从输入范围中读取元素;然后将他们复制到目标vec;

replace(ilst.begin(),ilst.end(),0,42);//这个调用将所有值为0的实例替换成42;

replac_copy(ilst.begin(),ilst.end(),back_inserter(vec),0,42);//调用这个函数后。ilst并没有变,vec存储ilst的一份副本,而ilst内所有的0在vec中都被变成了42;

sort(beg,end);//按指定要排序的范围,使用<操作符比较元素,假如vec中有元素:af,cuc,xdd,bc;sort(vec.beg,vec.end);;//执行结果:af,bc,cu,xd

unique(beg,end);//返回一个迭代器表示无重复的值范围的结束。、、例如:vec中ab,fax,ab,bc,fax,abb,xd;;unique(vec.begin(),vec.end());结果:ab,abb,bc,fax,xd,ab,fax

                                 假如返回值为unique_end,然后使用vec.erase(unique_end,vec.end());就可以删除ab,fax;unique_end指向后面的那个ab;

#include <iostream>
#include <string>
#include <iterator>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;
bool isShoter(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 nextword;
	while(cin>>nextword)
	{
		words.push_back(nextword);
	}
	stable_sort(words.begin(),words.end(),isShoter);
	vector<string>::iterator end_unique=unique(words.begin(),words.end());
	words.erase(end_unique,words.end());
	vector<string>::size_type num=count_if(words.begin(),words.end(),GT6);
	for (vector<string>::iterator iter=words.begin();iter!=words.end();++iter)
	{
		cout<<*iter<<" ";
	}

	return 0;
}

抱歉!评论已关闭.