Here is the description:
CHALLENGE DESCRIPTION:
You are given a text. Write a program which outputs its lines according to the following rules:
- If line length is ≤ 55 characters, print it without any changes.
- If the line length is > 55 characters, change it as follows:
- Trim the line to 40 characters.
- If there are spaces ‘ ’ in the resulting string, trim it once again to the last space (the space should be trimmed too).
- Add a string ‘...
’ to the end of the resulting string and print it.
Trimming to 40 characters to me would mean... line.substring(0,40); //(JAVA)
I was really confused at why non of the read-more example output stopped in the middle of a word.
Because of a bad example, I couldn't figure out if that was co-incidental or by design.
Example: With the input:
123456789 123456789 123456789 123 Supercalifragilisticexpialidocious
I was pretty sure due to the instructions, the proper output would be something like this:
123456789 123456789 123456789 123 Superc... Read More
But the correct answer is more like:
123456789 123456789 123456789 123 //Notice the absence of the sliced in half "Superc"
So... What they are actually asking you to do is:
If the line is > 55 characters:
1. Tokenize the line using " " as a delimiter.
2. Build the string back up, stopping before you go over 40 characters.
3. If you get a zero-length string this way, just do line.substring.split(0,40);
I hope this helps someone.
Judging by everything I read on the internet.
I seem to be the only one who couldn't make sense of the instructions.
I really hate problems where the majority of why I can't solve it is because I don't know
what it is asking.
Today definitely re-affirms my grandfather's saying:
"A problem well stated is a problem half solved."
Thank you for this. I was going insane trying to figure this one out. I kept getting 95% due to the bad directions. I wanted you to know you are not the only one who read it that way.
ReplyDeleteSame here. Been doing this for almost 2 hours and COULD NOT figure out what I was doing wrong.
ReplyDeleteAnyone know how to report a badly worded challenge? Cause yeah, you guys are right. FYI - found a java answer that someone can use as reference:
ReplyDeletehttps://github.com/mirandaio/codeeval/blob/master/easy/ReadMore/Main.java