Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This file is for generating sample input data.
- */
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- // input
- String a = in.next();
- String b = in.next();
- // find the largest common substring between Strings a and b
- int n = a.length(), m = b.length(), sz = 0;
- String commonSubstring = "";
- for(int len = 1; len <= Math.min(n, m); len++) {
- for(int i = 0; i + len <= n; i++) {
- for(int j = 0; j + len <= m; j++) {
- if(a.substring(i, i + len).equals(b.substring(j, j + len))) {
- sz = Math.max(sz, len);
- commonSubstring = a.substring(i, i + len);
- }
- }
- }
- }
- // output
- System.out.println("Largest Common Substring: " + commonSubstring);
- System.out.println("String Size: " + sz);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment