+ 6

[ANSWERED] Finding a specific element in a vector

I'm having problems with the following code. The code is meant to generate ranks of number listed in a vector. Allow me to describe the problems. 1. I try to use std::lower_bound to find a specific number, I do this in attempt to deduce the rank of the number in another vector, which is sorted in descending order. But I can't make it work except the vector is sorted in ascending order. 2. Then I try to use std::find which works for me, but I was getting the impression that I would do better with std::lower_bound because the latter is said to perform better with a sorted container. Read the next for a question in regards to std::find. 3. std::find is giving me the same result when there are similar numbers in the vector. How do I get different result? as I need to figure out the index of the number which obviously be different. Here is the code, please help with suggestions, corrections or links to guide me. T.I.A 🙏 https://code.sololearn.com/cbhXoI4R4eRU/?ref=app

3rd Mar 2020, 11:06 AM
Ipang
8 Réponses
+ 3
~ swim ~ Idk what to say 😂 I would think the board maybe puts a "hold back" because they wanted to be sure that everything was okay before publishing. As if they probably wanted a triple or quadruple quality control checks which slows things down. That's nice idea they got, but I agree with you about backward compatibilty and performance issue. It is indeed a dilemmatic trade between keeping the language as performant or make it "well equipped". Like choosing a lightweight infantry opposed to a whole brigade with everything packed in (which obviously isn't as performant in moving) hehehe 😆
4th Mar 2020, 2:00 PM
Ipang
+ 2
~ swim ~ Thank you so much for helping me, and many other members of this community 🤗 If you don't mind I have one doubt, that is I am not really understanding the difference between `lower_bound` and `upper_bound`. I have read the cppreference, but I seem to fail understanding still. I tried `upper_bound` for same purpose in that code, but I had no luck. I guess it's because I'm doing it wrong. Looks like I need a bit of help with those two (`lower_bound` and `upper_bound`). When you got the time of course 🙏
4th Mar 2020, 3:19 AM
Ipang
+ 2
~ swim ~ Thank you! that was loads less confusing than cppreference intro on lower_bound and upper_bound. Idk why I stumble upon reading the reference every now and then. But I kinda like the extra details about syntax compared to, say ... cplusplus. Thank you very much 🙏
4th Mar 2020, 11:24 AM
Ipang
+ 2
~ swim ~ I'm not too familiar with the standards as I'm just a learner, but yeah I recall cplusplus only has C++11 tab available. Is C++20 out just yet? I was interested as cppreference said string::starts_with and ends_with will be included. Not that it matters, but other languages came with that long time ago. It's a bit shame C++ had to wait so long just for such features : )
4th Mar 2020, 11:43 AM
Ipang