In the main method, read the name of a file that contains words separated by spaces from the console.
In the text of the file, find all pairs of words that are mirror images of each other. Add them to result.
Use StringBuilder.
The file encoding is UTF-8.
Inverted words
- 24
Locked
Comments (13)
- Popular
- New
- Old
You must be signed in to leave a comment
wang gang
24 July 2021, 03:55
1.theString first in the pair is always less than to second
2.don't filter repeated pair
+2
DarthGizka
9 June 2021, 18:58
task2207 (Inverted words) UNDOCUMENTED REQUIREMENTS: the validator rejected my first solution, which looked only for *consecutive* mirror pairs (since this was fully compatible with the task description and the examples).
The validator accepted my second solution, which found mirror pairs regardless of how many other words were between them. These pairs were output in the order they were matched up (i.e. an output pair was generated at the point where the second part appeared in the input sequence).
It would have been easy to add a non-consecutive pair to the examples or to mention this somewhere. But they didn't. And this isn't the first time that a task description was not only incomplete but deliberately misleading. Perhaps someone needs to be reminded who is paying whom here... 🙄
I would have given this task a double upvote if it weren't for this deliberate sabotage. Ergo double downvote.
0
Guadalupe Gagnon
4 November 2021, 15:33
The requirements do not say to find consecutive pairs. This was a phantom requirement you invented on your own.
+2
Adrian
3 March 2021, 17:38
Maybe it will give someone ideas, but what I did was:
*read the file contents into words and added it to an arraylist
*reversed each individual word and checked for the reversed word it in the arraylist.
* also made a special check for words that are palindromes (like "toto"---> when these words are reversed they look the same. to make sure the algorithm doesn't count these words twice I put a marker on them.
* if the word list .contains(reversed word) put both the original word and reversed in results.
*remove or edit both words so they are no longer counted.
0
Switch/Cypher
26 October 2020, 11:19
Just a fight against the validator. I made several solutions that were better than the 'answer' they provided and none were validated.
Also - why does StringBuilder need to be in main? I pushed all of the pair code into a separate method as is better practice and had to just put a random StringBuilder object in main just to pass.
Also - it needs to be much clearer what you want in result at the end. 'All pairs of words that are mirror images of each other' just isn't clear enough. What if the file was 'tot(1) tot(2) tot(3) tot(4)'? Output should be:
tot1 tot2
tot1 tot3
tot1 tot4
tot2 tot3
tot2 tot4
tot3 tot4
but that isn't what you want.....
0
Adrian
3 March 2021, 17:23
Wait, they provide answers??
0
Andrei
30 March 2021, 12:49
lmao yes, for a while now, you did not know? Check the image I attached. ![]()

0
Adrian
3 April 2021, 04:38
oh I have been slaving away hahaha! I had no idea.
+1
Andrei
5 April 2021, 07:24
well, don't feel bad because in a way it's better the way you did it, as you did not have the temptation of a ready solution available.. so working hard you understood more. 💪👍
+1
Agent Smith
26 September 2020, 20:54
Make sure to actually print the resulting pairs to console in the end.
+1
BlueJavaBanana
6 July 2020, 12:58
CHECK YOUR CODE WITH THIS
INPUT:
rat tar tart a
a tot tot tot rat
tot a tot
OUTPUT:
rat tar
a a
tot tot
tot tot
It seems you only match each individual word ONCE but if that word appears again later on and it too has a match you add that as well.
Also don't just check if the next word is mirrored, if the next word does not mirror, look at all the rest of the words. If you find a match, you can't use that word again (I think!)
+5
Jomar TayactacExpert
30 May 2022, 16:43
Made adjustments based on this and it made my code passed. Cheers!
0
Yiheng Niu
26 March 2020, 04:49
Attention: The mirror images can be the same.
+1