Question: Programming Challenge Description: You will be given a sequence of passages, and must filter out any passage whose text (sequence of whitespace-delimited words) is wholly

Programming Challenge Description:

You will be given a sequence of passages, and must filter out any passage whose text (sequence of whitespace-delimited words) is wholly contained as a sub-passage of one or more of the other passages.

When comparing for containment, certain rules must be followed:

The case of alphabetic characters should be ignored

Leading and trailing whitespace should be ignored

Any other block of contiguous whitespace should be treated as a single space

non-alphanumeric character should be ignored, white space should be retained

Duplicates must also be filtered - if two passages are considered equal with respect to the comparison rules listed above, only the shortest should be retained. If they are also the same length, the earlier one in the input sequence should be kept. The retained passages should be output in their original form (identical to the input passage), and in the same order.

Input:

For each test case a single line comprising the passages (strings) to be processed, delimited by | characters. The | characters are not considered part of any passage.

Output:

A single line of filtered passages in the same |-delimited format.

Test 1

Test Input

Download Test Input

IBM cognitive computing|IBM "cognitive" computing is a revolution| ibm cognitive computing|'IBM Cognitive Computing' is a revolution? 

Expected Output

Download Test Output

IBM "cognitive" computing is a revolution 

Test 2

Test Input

Download Test Input

"Computer Science Department"|Computer-Science-Department|the "computer science department" 

Expected Output

Download Test Output

Computer-Science-Department|the "computer science department" 

Code to be completed in JAVA:

import java.io.*;

public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s; while ((s = in.readLine()) != null) { System.out.println(s); } } }

or Code to be completed in C++:

#include #include using namespace std;

int main() { string line; while (getline(cin, line)) { cout << line << endl; }

(the code it in python or scala or c# too will be appreciated if coding in these languages is not possible)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!