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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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