Searching for the right lines

  • 12
  • Locked
Read a file name from the console. Display all of the file's lines that contain only 2 words in the words list. Close the streams. Example: words contains the words A, B, and C Lines: C B A D // 3 words from words, rejected A B A D // 3 words from words, rejected D A D // 1 word from words, rejecte
You can't complete this task, because you're not signed in.
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Guadalupe Gagnon
Level 37 , Tampa, United States
11 October, 19:34
This should be mentioned, but it is not: searching for "words" is an incorrect description. The task should take each line, split it into substrings by the space char, then see if any of those sub strings match the Strings in the list. So, if the list had these Strings: ["file", "view", "In"] and the file had these lines: "in in xyz qwerty 12345" -- ("in" does not match "In") "file! code. view? klmno xyzw" -- ("file!" and "view?" do not match "file" and "view") Both of these would have 0 matches
Robert
Level 27 , Lombard, United States
1 November 2020, 20:16
If anyone else has issues with this one not passing the last requirement here is a hint to learn from my stupidity. You are ONLY suppose to display the accepted line. I was trying to display the wordcount plus "accepted or rejected" as they show in the example and kept failing. Using the example above, it may make more sense if it added what the expected output is which is: " Output: D A B D D A A D " Or maybe I'm the only one with issues on this one. :)
Roman
Level 41
2 November 2020, 06:40
from the condition:
Lines:
C B A D // 3 words from words, rejected
A B A D // 3 words from words, rejected
D A D // 1 word from words, rejected
D A B D // 2 words from words, accepted, display it
D A A D // 2 words from words, accepted, display it