Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
thanks, just added them.
Hi, I did a C++ translation. Let me know if it is ok! :D
This comment is hidden because it contains spoiler information about the solution
Thanks for the kata. I really like it. I was stuck on this for a while. If you're stuck, writing out the substrs for "baceb" on paper and look for patterns can help. It helped me.
@Chrono79 - Thanks for the tip, I'll definitely remember that after this!
@Exterminator - No problem, thank you for the learning experience. ^.^
I found out instead of using str directly. You can make a copy of it and use that. So you would do something like,
std::string strcopy = str;
char cstr = const_cast<char>(strcopy.c_str()); // changed str.c_str() to strcopy.c_str()
Or you can delete the '&' from the function instead of making a copy. Now it should pass, but I am not sure if it is the best approach.
All right, so I think I figured out what's wrong. I believe your code isn't wrong. But, there's an odd problem with it. When I do the random tests, I'll run your function, then after I'll run my function and it checks if we come up with the same answer. The problem is, when it runs your function, it is modifying my test string. I am not sure how, but in your code, you check for a space or " ". But for some reason, for each string with multiple spaces, it will delete single spaces and mash the strings together when there's multiple spaces and make it the new test string.
For example, if the original string was ( str = "food pizza spinach codewars" ). Your solution will get the correct word out, whichever one that will be. Then after that, I'll run my function to go through the string. And because your code somehow modified my string, my function will use ( str = "foodpizza spinachcodewars" ) and my function will pick the bigger one from this new modified string. You can actually see the modification if you put this in your code
std::cout << "orginal: " << str << "\n\n"; // prints string
char *pch; // put it above this line
std::cout << "now : " << str << \n\n"; // prints string
return ostr; // put it above this line
Also #include if you haven't. I honestly don't know why it does that, my guess it has something to do with your pointers modifying my string somehow even if it is const. ¯\(ツ)/¯
It looks like you are approaching the problem more like it is in C. I don't really know much about some details of C, so I am not sure what to suggest. Have you tried doing the C version of this problem?
All right, I checked it out real quick, and I am not sure what it could be. I ran the input you sent, and I get "inrpahbtnftueiearpnkeras" as the solution as well. I also get the same scores as you on all the words so that might be a good sign. Just wondering, do you also pass the edge test cases? I didn't print out each case out for the random tests, so when you're printing them, are you printing "\n\n" so strings don't overlap? It seems odd "pkhh" is showing as the expected answer since I am not getting it. My best guess it could be the next random case. I am not really sure.
oops, sorry, I'll check it out right now!
Thank you - will do!
Hi, I made a C++ translation. The author hasn't been on since 2016. Could someone check/approve it? :)
Hi, I made a C++ Translation. It is my first translation, so please let me know if there's something wrong! :D
Had to start off the new year working on one of your problems, g964! It was kind of difficult to understand at first. I read the problem about 100 times, but I think I was approaching and relating it the wrong way. This is a good practice in your use of data structures and sorting in C++, I think. It was fun.
Sorry for my multiple solution submits. I didn't realize when I edited them, it would submit a whole new one instead of editting the current one. D: