Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 19, 2016 05:42
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/de154d443a1434094260 to your computer and use it in GitHub Desktop.
Save jianminchen/de154d443a1434094260 to your computer and use it in GitHub Desktop.
Two string - using 'z'-'a' in array declaration, use one array size of 26, second one is to use a string.
using System;
using System.Collections.Generic;
using System.IO;
class Solution {
static void Main(String[] args) {
int lines = Convert.ToInt32(Console.ReadLine());
while(lines-- > 0)
{
bool[] founded = new bool['z' - 'a' + 1];
bool found = false;
char[] firstWord = Console.ReadLine().ToCharArray();
foreach (char c in firstWord)
founded[c - 'a'] = true;
char[] secondWord = Console.ReadLine().ToCharArray();
foreach (char c in secondWord)
{
if (founded[c - 'a'])
{
found = true;
break;
}
}
Console.WriteLine(found ? "YES" : "NO");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment