MᏫᎻᎯᎷᎷᎬᎠ
World Mobile Token Community
Kindly provide the name for this book
olli
it's the standard
olli
you can read one of the latest drafts at
http://eel.is/c++draft/
BinaryByter
BinaryByter
olli
you're welcome :)
olli
several implementations i am aware of thread std::vector<bool> as a bitset
BinaryByter
though std::vector<bool> that acts as a bitset is dangerous
BinaryByter
since bitsets are slow
olli
welcome to c++ - there have been several discussion about this
BinaryByter
BinaryByter
though you should optimize both
olli
don't agree - it depends
BinaryByter
I was talking about modern pc
BinaryByter
obviously you know some fucked up pc's that need extra requirements
olli
it's about embedded
BinaryByter
stop doing fucked up things
Sonu
Okay
BinaryByter
also, you have a pointer to an array
MᏫᎻᎯᎷᎷᎬᎠ
Daamn!!!
BinaryByter
Sonu
Nevermind
Sonu
Thanks
BinaryByter
#cpp
Marie
#cpp
https://t.me/programminginc/24103
klimi
Sonu
BinaryByter
klimi
klimi
#ot
Marie
#ot
Offtopic group: https://t.me/joinchat/Ci0Cak-BPuxaHdcbjab4QQ
klimi
Do you like it ? :3
klimi
klimi
Just link
BinaryByter
oh
klimi
Isbt it cool?
BinaryByter
it is
klimi
Yay
klimi
Thanks :3
yuuki
Hey guys, anyone up for a challenge?
MᏫᎻᎯᎷᎷᎬᎠ
Gi ahead
MᏫᎻᎯᎷᎷᎬᎠ
O
yuuki
This is a question I was asked today by my friend... Got me stumped for the whole day...
MᏫᎻᎯᎷᎷᎬᎠ
I'm listening
yuuki
The question is, to print the count of minimum number of characters to be added to a string to make it a palindrome..
For example,
1. aba is a palindrome, so the function returns 0.
2. abca is not a palindrome, but, it can be made into one by adding a 'b' After the 'c'... So, it should return 1.
yuuki
How would you guys go about it?
klimi
Oh that's a nice challenge
yuuki
I still don't know the answer... I Did get one way to solve it..
Anonymous
Anonymous
for example abbca
Anonymous
this can be done by changing the order
yuuki
for example abbca
I don't think changing is part of the question... Insertions only for now..
yuuki
MᏫᎻᎯᎷᎷᎬᎠ
yuuki
Okay, no problem. I'll dry run an example to show what it needs to do.
So, the given string is : "abbca"
This is not a palindrome.
What can you add to this string to make it one?
Two consecutive 'b' After the occurrence of 'c'
Then, the string becomes "abbcbba"
Which is a palindrome!
So, the function should somehow find the number of characters to add and return it..
*minimum number of characters*
Anonymous
Anonymous
you just do a counting sort
Anonymous
then make sure that each character has an even number
Anonymous
if we cannot change it
MᏫᎻᎯᎷᎷᎬᎠ
Anonymous
then we have a more complex algorithm
Anonymous
what i would do in that case is compare the first and last character
yuuki
Anonymous
you have a pointer to the end
Anonymous
and to the beginning
Anonymous
you go down the list
Anonymous
if the characters match it is a palindrome
Anonymous
for all instances
Anonymous
klimi
XD
MᏫᎻᎯᎷᎷᎬᎠ
Anonymous
if not then we insert that character after
Anonymous
so here is an example in C pseudocode
MᏫᎻᎯᎷᎷᎬᎠ
That's a good way to deal with thing🤣
Anonymous
ssize_t i = 0;
ssize_t j = strlen(str) - 1;
int ret = 0;
for (;i < j; ++i, --j) {
if (str[i] == str[j])
continue;
char tmp = str[i];
++ret;
for (ssize_t k = j + 1; k < strlen(str); ++k) {
tmp ^= str[k];
str[k] ^= tmp;
tmp ^= str[k];
}
++j;
}
Anonymous
now str has to be at least twice as big as the original string