1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| import java.util.Scanner;
public class Diff { static String s1,s2; static String[] word1; static String[] word2;
static void input() { Scanner input = new Scanner(System.in); s1 = input.nextLine(); s2 = input.nextLine(); int len1 = s1.length(); int len2 = s2.length(); } static String process(String A, String B) { String common=""; word1 = A.split(" "); word2 = B.split(" "); int len1 = word1.length; int len2 = word2.length; for(int i=0;i<len1;i++) { for(int j=0;j<len2;j++) { int pos = word2[j].indexOf(word1[i]); if(pos!=-1) { word2[j] = word2[j].substring(0,pos) + word2[j].substring(pos+word1[i].length()); common = common + word1[i]; break; } } } return common; } static String declan(String c1, String c2) { String ans=""; int len1 = c1.length(); for(int i=0;i<len1;i++) { String tmp = c1.substring(i, i+1); int pos = c2.indexOf(tmp); if(pos==-1) continue; ans = ans + tmp; c2 = c2.substring(pos+1); } return (ans=="")?("NONE"):(ans); } public static void main(String[] args) { for(int i=0;i<5;i++) { System.out.println("Please enter No."+(i+1)+" line of the input data:"); input(); String common1 = process(s1,s2); String common2 = process(s2,s1); System.out.println("The answer to No."+(i+1)+"line is:"); System.out.println(declan(common1,common2)); } System.out.println("All output done..."); System.out.println("Thanks for your testing"); } }
|