标签:vector 大小 bsp ras space out cto 整理 str
之前总结了一下我觉得有用的erase,lower_bound,upper_bound。
如:
sz = unique(b + 1,b + n + 1)-(b + 1);
sz = unique(a,a + n) - a;
对比一下lower_bound:
pos=lower_bound(b + 1,b + sz + 1,a[i]) - b;
sort(words.begin(), words.end()); vector<string>::iterator end_unique = unique(words.begin(), words.end()); words.erase(end_unique, words.end());
#include <iostream> #include <cassert> #include <algorithm> #include <vector> #include <string> #include <iterator> using namespace std; int main() { const int N=11; int array1[N]={1,2,0,3,3,0,7,7,7,0,8}; vector<int> vector1; for (int i=0;i<N;++i) vector1.push_back(array1[i]); vector<int>::iterator new_end; new_end=unique(vector1.begin(),vector1.end()); //"删除"相邻的重复元素 assert(vector1.size()==N); vector1.erase(new_end,vector1.end()); //删除(真正的删除)重复的元素 copy(vector1.begin(),vector1.end(),ostream_iterator<int>(cout," ")); cout<<endl; return 0; }
(代码当然是舶来品。。。)
标签:vector 大小 bsp ras space out cto 整理 str
原文地址:http://www.cnblogs.com/hua-dong/p/7943983.html