8000 solved 0x16 7662 · jo0n-lab/basic-algo-lecture@3c25cd3 · GitHub
[go: up one dir, main page]

10000 Skip to content

Commit 3c25cd3

Browse files
author
cuberry
committed
solved 0x16 7662
1 parent afa3713 commit 3c25cd3

File tree

7 files changed

+79
-0
lines changed

7 files changed

+79
-0
lines changed

0x16/stl_example.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ void set_example(){
55
set<int> s;
66
s.insert(-10); s.insert(100); s.insert(15); // {-10, 15, 100}
77
s.insert(-10); // {-10, 15, 100}
8+
89
cout << s.erase(100) << '\n'; // {-10, 15}, 1
910
cout << s.erase(20) << '\n'; // {-10, 15}, 0
11+
// returns 1 if deleted target or 0
12+
1013
if(s.find(15) != s.end()) cout << "15 in s\n";
1114
else cout << "15 not in s\n";
15+
// returns pos of target or *.end()
16+
// ... alone itself not suggested -> with s.end() check
17+
1218
cout << s.size() << '\n'; // 2
1319
cout << s.count(50) << '\n'; // 0
20+
// returns num of target
21+
1422
for(auto e : s) cout << e << ' ';
1523
cout << '\n';
1624
s.insert(-40); // {-40, -10, 15}
File renamed without changes.

0x16/v7662/main

28.1 KB
Binary file not shown.

0x16/v7662/main.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

0x16/v7662/tc1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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

0x16/v7662/test/main

26.4 KB
Binary file not shown.

0x16/v7662/test/main.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

0 commit comments

Comments
 (0)
0