Anonymous
I don't like this code
Anonymous
I don't like this code
You are not understanding me.
Anonymous
I'm saying - Is is prone to errors? That's it
Anonymous
You are not understanding me.
Your code is jsut not readable
Anonymous
It is
yeah
Anonymous
It is
Why is it erroneous?
Anonymous
Right now, I don't want my code to be of someone else's liking.
Anonymous
In the first place you are using really BAD variables names
I_Interface
for(int i=0;i<a.length()-2;++i){ ans = max(ans,r[i+1] - l[i]-1); }
and yes, lenght method returns std::size_t type, what is not int type, u must be get a warning
Anonymous
In the first place you are using really BAD variables names
My gosh. don't you hear that "Right now, I don't want my code to be of someone else's liking."
Anonymous
When you write your code, follow this quote: Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
I_Interface
So, if i typecast it to int. Would that be good?
std::size_t i in "for" loop
Anonymous
It not about liking
Anonymous
It is about badness
Mat
Yes, but this code is not for development. It is just for me. Do you hear that. Just for me.
That doesn't mean you shouldn't use the best way of doing something
Mat
Yeah, your method has more possibilities of having something wrong without you notice it
Anonymous
That doesn't mean you shouldn't use the best way of doing something
Sir, I'm doing competitive programming and here we are expected to be fast with our solutions.
Anonymous
Just imagine that you are not able to code for weeks Then you come back to the code, when you forget about it, and see this You will waste a ton of time just to trying understand this
Mat
Sir, I'm doing competitive programming and here we are expected to be fast with our solutions.
That doesn't mean you should use bad code. The key about challenges is how fast you can write GOOD code
Mat
Good code means less and clearer errors, less and more readable code written
Anonymous
Please end this discussion on BAD and GOOD code. I understand what you want to say. But, that's not what I came here to ask.
I_Interface
Good code means less and clearer errors, less and more readable code written
Mat, when i should use STL loop ? and is it better than raw loop ?
Anonymous
Good code means less and clearer errors, less and more readable code written
Yes, code readability is not what I need right now.
Mat
If you don't remember what a function or a snippet do during a competition, you're out of luck. If you can't get where your error is because you wrote bad code you lose
Mat
That's kinda simple. Think that bad code is faster to write/use/read is really bad and will not get you to the win
Anonymous
If you don't remember what a function or a snippet do during a competition, you're out of luck. If you can't get where your error is because you wrote bad code you lose
Sir, Leave the code readabiltiy to myself. I just have a code of 70-80 lines and Im not dumb to remember the name of variables.
Anonymous
Anonymous
I don't think so.
Mat
Yes
Anonymous
So let's get back to the question I was asking.
Mat
If it's an highly enough number, I'll think you know what you're saying
Mat
But during debugging, I found that the loop was getting executed twice or thrice
Do you mean with bad code you couldn't get what's wrong?
Anonymous
+
it is C++98 version of range-based for
Mat
That's just something the compiler will translate in something it likes
Anonymous
I think range-based for is ok, but I think that almost always loops should be separated in functions
Anonymous
std::size_t i in "for" loop
a is string mp1 and mp2 are maps here So, should it be : for(std::size_t i=0;i<a.length()-2;++i){ ans = max(ans,mp1[i+1] - mp1[i]-1); } But, Isn't indexing maps with size_t wrong? Idk
Anonymous
indexing maps itself is wrong lol
If we know the key then is that a wrong way to find its value.
Mat
If we know the key then is that a wrong way to find its value.
Read the library... You can't access map's members this way...
Anonymous
indexing maps itself is wrong lol
I thought there is a [] operator that works on std::map
Anonymous
Read the library... You can't access map's members this way...
http://www.cplusplus.com/reference/map/map/operator[]/
Mat
Using a KEY, not an iterator
Mat
Do you know what a map is?
Anonymous
I thought there is a [] operator that works on std::map
There is It is an overloaded operator to have access to a value by a key std::map doen's have indexes
Anonymous
mp1[i+1]; mp1 is a map<int,int> In my code i+1 is a key and not an iterator.
Anonymous
for(int i=0;i<a.length()-2;++i){ ans = max(ans,mp1[i+1] - mp1[i]-1); } i+1 are keys and not iterators.
Anonymous
really baaaaaaaaaaaaaaad code
Anonymous
please clarify my doubts.
Anonymous
I've here for so long asking it.
Mat
for(int i=0;i<a.length()-2;++i){ ans = max(ans,mp1[i+1] - mp1[i]-1); } i+1 are keys and not iterators.
You can do it if you're using your map as an array of ints. And the variable a where you call length doesn't exists now
Anonymous
Leave the maps, how can i iterate to the length of a -2? for(int i=0;i<a.length()-2;++i){ }
Anonymous
Ajay, what do you think how std::map::operator[] is going to behave if it doesn't find a key, you passed?
Mat
Leave the maps, how can i iterate to the length of a -2? for(int i=0;i<a.length()-2;++i){ }
This is the right thing. Probably I would use something else but for your knowledge that's the right way
Anonymous
So
Anonymous
Considering that length of a is 1
Anonymous
Then doesn't a.length()-2 becomes unsigned?
Anonymous
I mean what will .length()-2 be
Mat
That's UB
Anonymous
a.length() is unsigned
Anonymous
That's UB
it is not
Anonymous
and unsigned -2 is what?