标签:style blog color os io for div log
#include <algorithm>
1. max_element(v.begin(), v.end());
2. min_element(v.begin(), v.end());
3. find(v.begin(), v.end(), 3);
4. sort(v.begin(), v.end());
5. reverse(pos, v.end();
1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 using namespace std; 5 6 int main() { 7 vector<int> v; 8 vector<int>::iterator pos; 9 10 for(int i = 6; i >= 1; i--) 11 v.push_back(i); 12 13 pos = max_element(v.begin(), v.end()); 14 cout << "the max element is: " << *pos << endl; 15 16 pos = min_element(v.begin(), v.end()); 17 cout << "the min element is: " << *pos << endl; 18 19 sort(v.begin(), v.end()); 20 21 pos = find(v.begin(), v.end(), 3); 22 23 reverse(pos, v.end()); 24 25 for(pos = v.begin(); pos != v.end(); pos++) 26 cout << *pos << " "; 27 28 29 return 0; 30 }
输出:
$ ./a.exe the max element is: 6 the min element is: 1 1 2 3 6 5 4
标签:style blog color os io for div log
原文地址:http://www.cnblogs.com/dracohan/p/3919317.html