Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 19, 2016 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/213335b4dec3988facfe to your computer and use it in GitHub Desktop.
Save jianminchen/213335b4dec3988facfe to your computer and use it in GitHub Desktop.
Two string - use Hashtable - code can be more readable
using System;
using System.Collections;
using System.IO;
class Solution {
static void Main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
int N = Convert.ToInt32(Console.ReadLine());
for( int i=0; i<N; i++ ) {
string A = Console.ReadLine();
string B = Console.ReadLine();
int lenA = A.Length;
int lenB = B.Length;
Hashtable ht = new Hashtable();
for( int c=0; c<lenB; c++ ) {
if( !ht.ContainsKey(B[c]) ) {
ht.Add(B[c],null);
}
}
string result = string.Empty;
for( int c=0; c<lenA; c++ ) {
if( ht.ContainsKey(A[c]) ) {
result = "YES";
break;
}
}
if( result==string.Empty ) result = "NO";
Console.WriteLine(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment