vector

1
2
3
4
5
6
7
8
9
vector<int> a(n);
// pair
vector<pair<int, int>> b;
b.push_back({1, 2});

// 遍历
for(const auto& [a, b] : b){
cout << a << " " << b << endl;
}

哈希表

1
2
3
4
5
6
7
8
map<int, int> mp = {
{0, 1}, {4, 1}, {6, 1}, {9, 1}, {8, 2}
};
mp.find(digit) != mp.end()
map<int, PII> mp
for(auto &it : mp){
cout << it.firtst << " " << it.second.first << " " << it.second.second << endl;
}

readline

1
2
3
4
5
6
7
8
9
10
11
12
13
14
std::vector<T> input()
{
std::vector<T> a;
T s;
while (std::cin >> s)
{
a.push_back(s);
if (std::cin.get() != ' ')
break;
}
return a;
}
//用法
vector<int> a = input<int>();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
template <typename T>
vector<T> input()
{
vector<T> list;
string input;
getline(cin, input);
istringstream stream(input);
int number;
while (stream >> number)
{
list.push_back(number);
}
return list;
}
// 用法
vector<int> a = input<int>();