-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTL.cpp
More file actions
56 lines (49 loc) · 861 Bytes
/
STL.cpp
File metadata and controls
56 lines (49 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(1) vector
int n;
vector<int> v;
int main() {
scanf("%d",&n);
For(i,1,n) {
int x;
scanf("%d",&x);
v.push_back(x);
}
for(vector<int>::iterator it=v.begin(); it!=v.end(); ++it)printf("%d\n",*it);
return 0;
}
(2) priority_queue
重载“<”来定义优先级
struct Node {
int num,len;
};
bool operator <(Node x,Node y) {
return x.len>y.len;//len小的优先
}
priority_queue<Node> q;
重载“()”来定义优先级
struct Cmp {
bool operator ()(int &x,int &y) {
return x>y;//小的优先
}
};
priority_queue<int,vector<int>,Cmp> q;
(3) map
int n,m;
map<int,int> mp;
int main() {
scanf("%d",&n);
For(i,1,n) {
int x,y;
scanf("%d%d",&x,&y);
mp[x]=y;
}
scanf("%d",&m);
For(i,1,m) {
int x;
scanf("%d",&x);
map<int,int>::iterator it=mp.find(x);
if(it!=mp.end())printf("%d:%d\n",(*it).first,(*it).second);
else printf("Not found\n");
}
return 0;
}