-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
TwoStrings.java
43 lines (42 loc) · 1.3 KB
/
TwoStrings.java
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
import java.util.Scanner;
public class Solution {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
while((t--)!=0){
String a = sc.next() + " ";
String b = sc.next() + " ";
char s1,s2;
boolean equals = false;
int visited[] = new int[26];
try{
label:
for(int i=0;(int)(a.charAt(i))!=32;i++){
s1 = a.charAt(i);
if(visited[s1-97]==0){
try{
for(int j=0;(int)(b.charAt(j))!=32;j++){
s2 = b.charAt(j);
if(s1==s2){
equals = true;
break label;
}
}
}
catch(Exception e){
System.out.println("exception caught 1");
}
visited[s1-97] = 1;
}
}
}
catch(Exception e){
System.out.println("exception caught 2");
}
if(equals)
System.out.println("YES");
else
System.out.println("NO");
}
}
}