Secret Chat
https://judge.softuni.bg/Contests/Practice/DownloadResource/9007
So does anyone know the secret for the "Secret Chat" Problem written in java?
Here is my code https://pastebin.com/vNDULc7v receiving 87/100 by judge.
https://judge.softuni.bg/Contests/Practice/DownloadResource/9007
So does anyone know the secret for the "Secret Chat" Problem written in java?
Here is my code https://pastebin.com/vNDULc7v receiving 87/100 by judge.
The problem is on line #55:
msg = msg.replace(toCut, "").concat(new StringBuilder(toCut).reverse().toString());
String#replace method "Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence." while the task is to "... replace only the first occurrence of the given substring if there are more than one such occurrences."
String#replaceFirst method should be used instead for this task:
msg = msg.replaceFirst(toCut, "").concat(new StringBuilder(toCut).reverse().toString());
The change above will take you to 100/100 in Judge, but it will throw exception for any special character (like '?' which is used in Zero test #2) in toCut string as it is used as regex.
The simplest solution to this new problem is to use Pattern.quote:
msg = msg.replaceFirst(Pattern.quote(toCut), "").concat(new StringBuilder(toCut).reverse().toString());
As a bonus, this is the program refactored to use StringBuilder and BufferedReader which results in about 3 times faster execution according to Judge tests.
Thank you very much for this answer and all your Posts in the forum. You allways deep explaining the Problem and your additional code examples are very nice to gain more experience.
In fact, it is much easier to use black gay chat, because there is no secret code here and you can always find someone to strike up a casual conversation. In my opinion, this is a very good and proven offer for finding a friend. Recently, gay dating on the Internet and not only have become very popular, but all thanks to the fact that today there are many different gay sites in the world.