File tree Expand file tree Collapse file tree 7 files changed +79
-0
lines changed Expand file tree Collapse file tree 7 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,20 @@ void set_example(){
5
5
set<int > s;
6
6
s.insert (-10 ); s.insert (100 ); s.insert (15 ); // {-10, 15, 100}
7
7
s.insert (-10 ); // {-10, 15, 100}
8
+
8
9
cout << s.erase (100 ) << ' \n ' ; // {-10, 15}, 1
9
10
cout << s.erase (20 ) << ' \n ' ; // {-10, 15}, 0
11
+ // returns 1 if deleted target or 0
12
+
10
13
if (s.find (15 ) != s.end ()) cout << " 15 in s\n " ;
11
14
else cout << " 15 not in s\n " ;
15
+ // returns pos of target or *.end()
16
+ // ... alone itself not suggested -> with s.end() check
17
+
12
18
cout << s.size () << ' \n ' ; // 2
13
19
cout << s.count (50 ) << ' \n ' ; // 0
20
+ // returns num of target
21
+
14
22
for (auto e : s) cout << e << ' ' ;
15
23
cout << ' \n ' ;
16
24
s.insert (-40 ); // {-40, -10, 15}
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ int T;
5
+
6
+ int main () {
7
+ ios::sync_with_stdio (false );
8
+ cin.tie (NULL );
9
+
10
+ cin >> T;
11
+ for (int t = 1 ; t <= T; t++) {
12
+ multiset<int > s;
13
+ int k;
14
+ cin >> k;
15
+ for (int i = 1 ; i <= k; i++) {
16
+ char comm;
17
+ cin >> comm;
18
+ int n;
19
+ cin >> n;
20
+
21
+ if (comm == ' I' )
22
+ s.insert (n);
23
+ else {
24
+ if (s.empty ())
25
+ continue ;
26
+ if (n == 1 )
27
+ s.erase (prev (s.end ()));
28
+ else
29
+ s.erase (s.begin ());
30
+ }
31
+ }
32
+ if (s.empty ())
33
+ cout << " EMPTY\n " ;
34
+ else
35
+ cout << *prev (s.end ()) << " " << *s.begin () << " \n " ;
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ 2
2
+ 7
3
+ I 16
4
+ I -5643
5
+ D -1
6
+ D 1
7
+ D 1
8
+ I 123
9
+ D -1
10
+ 9
11
+ I -45
12
+ I 653
13
+ D 1
14
+ I -642
15
+ I 45
16
+ I 97
17
+ D 1
18
+ D -1
19
+ I 333
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ int main (){
5
+ set<int > s;
6
+
7
+ s.erase (0 );
8
+ cout<<*s.begin ()<<" \n " ;
9
+ cout<<*s.end ()<<" \n " ;
10
+
11
+ auto it=s.end ();
12
+ advance (it,1 );
13
+ cout<<*it<<" \n " ;
14
+
15
+ }
You can’t perform that action at this time.
0 commit comments