STL
Mason123456 · · 算法·理论
-std=c++14
VECTOR
vector<int> a;
for (int i = 0; i < a.size(); i++)
cout << a[i];
for (vector<int>::iterator p = a.begin(); p != a.end(); p++)
cin >> *p;
for (auto p = a.begin(); p != a.end(); p++)
cin >> *p;
for (int &x : a) cin >> x;
for (int x : a) cout << x << ' ';
vector<int> a;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a.push_back(x);
}
a.pop_back();
a[0] *(a.begin())
a.back() a[a.size()-1]
sort(a.begin(), a.end());
SET
set 集合,元素不重复且有序,复杂度
set<int> S;
看
S.count(x)
int n;
cin >> n;
while (n--) {
int x;
cin >> x;
S.insert(x);
}
while (!S.empty()) {
int x = *(S.begin());
cout << x << '\n';
S.erase(x);
}
PAIR
pair<int, long long> p;
p.first p.second
map<int, int> mp; //存key-value的pair,按key从小到大排序
mp[9] = 114; {9,114}
map<int, int> mp;
mp[1231] = 1;
mp[1] = 1122432;
mp[-12] = 444543;
mp[1231] = -1;
for (auto p = mp.begin(); p != mp.end(); p++) {
cout << (*p).first << ' ' << (*p).second << '\n';
}