Nisha
Can you write a code
Anonymous
Using
Yep, that's missing too
András
Can you write a code
Use snake_case for system words
András
int not Int and so on
Nisha
🆗
Anonymous
https://img.kingdev.nl/clion64_2019-11-07_14-26-49.png
Anonymous
I think the problem is that its a member function so there's the implicit this parameter, use it for the left hand side and the parameter as the right hand side
Anonymous
also, I think you're gonna have issues using that order with any of the standard algorithms and data structures
Anonymous
4. Please write a program in C or C++ that performs following function. An array of 10 3-digit integers is given as {129, 099, 856, 738, 011, 222, 409, 177, 363, 600}. Please sort the integers according to the sum of their digits.
Snir
hello,I'm trying to sub this string by input length(if any character appear,print it only once)like this example.any suggestions?thank you.
Snir
Snir
length 2
MilkBeforeCereal
How to solve it
get each digit and store sum in another array
MilkBeforeCereal
while sorting sum array, sort original array too
Anonymous
https://img.kingdev.nl/NVIDIA%20Share_2019-11-07_14-53-20.png
Anonymous
so somehow my Map its size is 1
Anonymous
I do add multiple elements tho to the map, And the key should be correct
Anonymous
bool operator <(const MyVector &a) const { return (a.x == this->x && a.y == this->y && a.z == this->z); }
Anonymous
?
Anonymous
@QNeko Yo need a operator like that for a map
Anonymous
because its not a strict weak order as required (its obviously reflexive)
Anonymous
you can try something like: bool operator<(const MyVector &rhs) const { return x < rhs.x && y < rhs.y && z < rhs.z; }
Anonymous
Jay it has to match the coords not be less
Anonymous
x has to be the same as the passed vector x
Anonymous
what is Fibonacci series
Anonymous
fibnonachi numbers
Anonymous
Series
Anonymous
In c program
Anonymous
1, 1, 2, 3, 5, 8, 13, 21, 34
Kirk
1 1 2 3 5 8 13 21 34 55 89 144 etc
Anonymous
:/ why exactly do you think < should be the same as ==?
Anonymous
as < is less then
数学の恋人
It's not a language, it is a joke
Then what's whitespace for you?
Anonymous
Ok something weird
Anonymous
the vector passed to the function is awlays 0 0 0
Anonymous
Write c program to Perform swapping of two number without using third number
Anonymous
[2019-11-07 15:16:37.148] [info] comp: 0 0 0 - 15 15 10 [2019-11-07 15:16:37.148] [info] comp: 15 15 10 - 0 0 0 [2019-11-07 15:16:37.148] [info] setVec 15 15 10 [2019-11-07 15:16:37.148] [info] comp: 0 0 0 - 15 15 11 [2019-11-07 15:16:37.148] [info] comp: 15 15 11 - 0 0 0
Anonymous
the f
Anonymous
its because of your operator< but you're not listening lol
Anonymous
/warn screen photo
Ludovic 'Archivist'
@QNeko Yo need a operator like that for a map
What leaves me weirded out is that it rather compare == elements but is written <
Ludovic 'Archivist'
Also, map will not work with that as being the same element in a map means !(a<b || b<a)
Ludovic 'Archivist'
bool operator <(const MyVector &a) const { return (a.x == this->x && a.y == this->y && a.z == this->z); }
Rather, I would have that be bool operator <(const MyVector &a) const { return this->x < a.x? true :( this->y < a.y? true :( this->z < a.z? true : false)); }
Ludovic 'Archivist'
It's three magic xors or there substractions
Better use modulo addition as xor can 0 the data instead if you swap identical values
Ludovic 'Archivist'
Rather, I would have that be bool operator <(const MyVector &a) const { if(this->x < a.x) return true; else if(this->x == a.x) { if(this->y< a.y) return true; else if(this->y == a.y) { if(this->z < a.z) return true; } } return false; }
Anonymous
Hu?
Anonymous
But the issue aint that
Anonymous
the issue is the passed pos to the compare func
Anonymous
Its passing 0 0 0 to it
Anonymous
https://img.kingdev.nl/2019-11-07_15-38-16.png
数学の恋人
Anonymous
if the passed vector coords are 0 ofc compare fails
Ludovic 'Archivist'
the issue is the passed pos to the compare func
Your comparison is not correct anyway so what you pass into it doesn't really matter
Ludovic 'Archivist'
https://img.kingdev.nl/2019-11-07_15-38-16.png
Also that issue ain't in that code
Ludovic 'Archivist'
If there's no overflow
Even if there is overflow if defined to be modulo arithmetic (the case in C and C++ for all unsigned integer types for example)
Anonymous
Hu?
The broken compare affects how the map behaves and is probably what is causing the (0, 0, 0) being passed to it too. Try a proper func for a second
Ilya
https://img.kingdev.nl/2019-11-07_15-38-16.png
yet another reason why screenshots of code must be firbidden
Ilya
https://img.kingdev.nl/2019-11-07_15-38-16.png
Do you really understand what operator < should do ?
Anonymous
hi
klimi
hi
数学の恋人
If there's no overflow
Yeah that's his problem
Pavel
Yeah that's his problem
No, I think he's right. Even if it overflows it produces the correct result (if the variables have the same type).
Pavel
I mean the code is correct and Ludovic is right
Anonymous
🤔
Vitaliy ◀️TriΔng3l▶️
This has a bug
What bug if you don't overload operator||?
Ludovic 'Archivist'
Or this->x < a.x || this->y < a.y || this->z < a.z?
It doesn't match the requirement for std::map
Vitaliy ◀️TriΔng3l▶️
It doesn't match the requirement for std::map
Which requirement? It's exactly the same logic as you've written if || isn't overloaded