how to make find function on set/multiset correspond to last element of that kind? like on multiset with elements 1 7 7 7 8 9 i want iterator pointing on last 7 on index 3.
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
how to make find function on set/multiset correspond to last element of that kind? like on multiset with elements 1 7 7 7 8 9 i want iterator pointing on last 7 on index 3.
Name |
---|
Just use upper_bound and then decrement the iterator once.
Thanks so does lower_bound and find function do thr same thing?
Nah, they both are different thing.
But you can always check that, if your iterator is pointing towards the correct element you want to find.
I dont get how are they different
Just search it on internet and you will get everything about it
ok thx
lower_bound
returns an iterator to the smallest element that is at least $$$x$$$.upper_bound
returns an iterator to the smallest element that is greater than $$$x$$$.i meant difference between lower_bound and find function
Imagine a set
s
of $$${1, 3, 5, 7}$$$. The followings will hold true:s.find(4) == s.end()
s.lower_bound(4) == s.find(5)
Hope that was clear.
so do u mean because 4 is not in the set it points to nothing?
Yes.
got it ty
wow, how did I not know you could use upper_bound on sets
yeah you can use it on sets and multisets but you have to use it like this st.upper_bound(x)
in this way the iterator pointing on last occurrence of the number and if the condition is false or the value in the iterator not equal the number then the number doesn't exist