Problem Code: SIMDISH , please point out any errors .....giving desired results but not getting accepted

https://www.codechef.com/viewsolution/27993689

/* package codechef; // don’t place package name! */

import java.util.Scanner;

class CodeChefSIMDISH {

public static void main(String[] args) throws java.lang.Exception {
	Scanner sc = new Scanner(System.in);
	try {
		int t = sc.nextInt();
		sc.nextLine();
		while (t-- > 0) {
			int flag = 0;
			String dish1 = sc.nextLine();
			String[] dish = dish1.split(" ");
			String dish2 = sc.nextLine();
			for (String k : dish) {
				if (dish2.contains(k)) {
					flag++;
				}
			}
			
			if (flag >= 2) {
				System.out.println("similar");
			} else
				System.out.println("dissimilar");
		}

	} catch (Exception e) {
	}

}

}

Consider the testcase:

1
ab ac ad ae
abacae sausage pickle eggs
1 Like