Created
March 26, 2016 03:26
-
-
Save jianminchen/21ffc64093fd5952647c to your computer and use it in GitHub Desktop.
Two string - Java - InputStream, OutputStream, System.in, System.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.io.BufferedReader; | |
import java.io.OutputStream; | |
import java.io.PrintWriter; | |
import java.io.IOException; | |
import java.util.StringTokenizer; | |
/** | |
* Built using CHelper plug-in | |
* Actual solution is at the top | |
*/ | |
public class Solution { | |
public static void main(String[] args) { | |
InputStream inputStream = System.in; | |
OutputStream outputStream = System.out; | |
InputReader in = new InputReader(inputStream); | |
PrintWriter out = new PrintWriter(outputStream); | |
TwoStrings solver = new TwoStrings(); | |
solver.solve(1, in, out); | |
out.close(); | |
} | |
} | |
class TwoStrings { | |
public void solve(int testNumber, InputReader in, PrintWriter out) { | |
int t = in.nextInt(); | |
for (int i = 0;i < t;i++) { | |
out.println(is(in.next(), in.next()) ? "YES" : "NO"); | |
} | |
} | |
private boolean is(String a, String b) { | |
boolean w1[] = new boolean[26]; | |
boolean w2[] = new boolean[26]; | |
for (char c : a.toCharArray()) w1[c - 'a'] = true; | |
for (char c : b.toCharArray()) w2[c - 'a'] = true; | |
for (int i = 0;i < 26;i++) { | |
if (w1[i] && w2[i]) return true; | |
} | |
return false; | |
} | |
} | |
class InputReader { | |
private BufferedReader br; | |
private StringTokenizer st; | |
public InputReader(InputStream in) { | |
br=new BufferedReader(new InputStreamReader(in)); | |
try { | |
st=new StringTokenizer(br.readLine()); | |
} catch (IOException ignored) { | |
} | |
} | |
public boolean readLine() { | |
try { | |
st=new StringTokenizer(br.readLine()); | |
} catch (IOException e) { | |
return false; | |
} | |
return true; | |
} | |
public int nextInt(){ | |
if(!st.hasMoreTokens()) readLine(); | |
return Integer.parseInt(st.nextToken()); | |
} | |
public String next(){ | |
if(!st.hasMoreTokens()) readLine(); | |
return st.nextToken(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment