QuestionQuestion

PROBLEM: A useful computer utility is to report the differences between two files. In this program, you will compare two strings to find common substrings.
The following algorithm will be used: Consider each character in turn in the first string. If it appears in the second string, add it to a resulting common string and delete all characters in the second string up to and including that character.
For example, the common string from abcddef to vdfaddwf is addf. The common string from vdfaddwf to abcddef is df.
INPUT: 5 lines of data. Each line will contain two strings, A and B. The strings will contain letters only and the strings will be separated by a single blank. Each string will have fewer than 64 characters.
OUTPUT: For each line, find the common string from A to B and from B to A going from left to right.
Then repeat the process going from right to left. This will produce 4 common strings. Print in alphabetical order all of the different letters that are contained in all 4 common strings. If there are none that are common to all 4 strings, print “NONE”.
SAMPLE INPUT http://www.datafiles.acsl.org/2019/contest2/int-sample-input.txt
abcddef vdfaddwf
friends afraid
delicious indiginous
shalom saaalaaam
happy shipshape
SAMPLE OUTPUT
1. df
2. dfir
3. iosu
4. ams
5. hp

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.*;

public class Diff{
   
public static void main(String args[]){
      
       Scanner scanner = new Scanner(System.in);
      
       for(int i = 0; i < 1; ++i){
            String input = scanner.nextLine();
            String[] words = input.split(" ");
            
            String common1 = getCommonString(words[0], words[1]);
            String common2 = getCommonString(words[1], words[0]);
            String common3 = getCommonString(reverse(words[0]), reverse(words[1]));
            String common4 = getCommonString(reverse(words[1]), reverse(words[0]))...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$43.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats