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 | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
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