- vector
#include <cstdio>
#include <vector>
using namespace std;
vector<int> name;
vector<vector<int> > name;
vector<int> name[size];
name[index];
vector<int>::iterator it = name.begin();
for(int i = 0; i < name.size(); i++) {
printf("%d ", *(it + i));
}
for(vector<int>::iterator it = name.begin(); it < name.begin(); it++) {
printf("%d ", *it);
}
name.push_back(x);
name.pop_back();
name.size();
name.clear();
name.insert(it, x);
name.erase(name.begin() + i);
name.erase(name.begin() + 1, name.begin() + 3) ;
- set
#include <cstdio>
#include <set>
using namespace std;
set<int> name;
set<int>::iterator it;
for(set<int>::iterator it = name.begin(); it != name.end(); it++) {
printf("%d ", *it);
}
name.insert(x);
set<int>::iterator it = name.find(x);
name.erase(name.find(x));
name.erase(x);
name.erase(name.find(x), name.end());
name.size();
name.clear();
- string
#include <cstdio>
#include <string>
using namespace std;
string std;
string std = "string";
str[i];
string::iterator = str.begin() + 3;
for(string::iterator it = str.begin(); it != str.end(); it++) {
printf("%c", *it);
}
#include <iostream>
cin >> str;
cout << str;
printf("%s\n", str.c_str());
+=
str = str1 + str2;
str += str1;
str.length();
str.size();
str.insert(pos, string);
str.insert(str.begin() + i, str2.begin(), str2.end());
str.erase(it);
str.erase(it1, it2);
str.erase(pos, length);
str.clear();
str.substr(pos, length);
string::npos
str.find(str2);
str.find(str2, pos);
str.replace(pos, len, str2);
str.replase(it, it2, str2);
- map
#include <cstdio>
#include <map>
using namespace std;
map<tp1, tp2> name;
map<char, int> mp;
mp['c'] = 20;
printf("%c", mp['c']);
map<char, int>::iterator it;
for(it = mp.begin(); it != mp.end(); it++) {
printf("%c %d\n", it->first, it->second);
}
it = mp.find('c');
mp.erase(it);
mp.erase('c');
mp.erase(it, mp.end());
mp.size();
mp.clear();
- queue 和 priority_queue
#include <cstdio>
#include <queue>
using namespace std;
queue<int> q;
q.front();
q.back();
q.push(i);
q.pop();
q.empty();
q.size();
priority_queue<int> pq;
pq.top();
pq.push(x);
int i = pq.top();
pq.pop();
pq.size();
pq.empty();
#include <functional>
priority_queue<int, vector<int>, less<int> > pq;
struct pen {
string name;
int price;
friend bool operator < (pen &a, pen &b) {
return a.price < b.price;
}
};
struct cmp {
bool operatro () (pen &a, pen &b) {
return a.price < b.price;
}
};
- stack
#include <cstdio>
#include <stack>
using namespace std;
stack<int> st;
st.top();
st.push(x);
st.top();
st.pop();
st.empty();
st.size();
- pair
#include <cstdio>
#include <utility>
using namespace std;
pair<int, string> p;
pair<int, string> p(1, "str");
p = make_pair(1, "str");
p.first; p.second;
map<string, int> mp;
mp.insert(make_pair(1, "str"));
mp.insert(pair<string, int> (1, "str"));
for(map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
cout << it->first << " " << it->second << endl;
}
- algorithm 头文件
#include <cstdio>
#include <algorithm>
using namespace std;
int a[10] = {1, 2, 3};
max(x, y);
min(x, y);
abs(x);
swap(x, y);
reverse(a + 1, a + 3);
reverse(it1, it2);
do {
printf("%d %d %d\n", a[0], a[1], a[2]);
}while(next_permutation(a, a + 3));
fill(a, a + 3, 123);
sort(a, a + 3);
bool cmp(int a, int b) {
return a > b;
}
sort(a, a + 3, cmp);
int* pos = lower_bound(a, a + 3, x);
int* pos = upper_bound(a, a + 3, x);
int a[10] {1, 2, 3, 3, 3, 3, 4, 5, 6, 6};
printf("[%d, %d)\n", lower_bound(a, a + 10, 3), upper_bound(a, a + 10, 3));