Created
March 19, 2016 05:47
-
-
Save jianminchen/213335b4dec3988facfe to your computer and use it in GitHub Desktop.
Two string - use Hashtable - code can be more readable
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
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