Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 19, 2016 01:38
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/50fc6b5a13b7d62dfa1d to your computer and use it in GitHub Desktop.
Save jianminchen/50fc6b5a13b7d62dfa1d to your computer and use it in GitHub Desktop.
Two strings - using C#, var, foreach, Any method - interesting to read
using System;
using System.IO;
using System.Linq;
public class Solution
{
static void Main()
{
#if DEBUG
Console.SetIn(File.OpenText("Input.txt"));
#endif
var t = Convert.ToInt32(Console.ReadLine());
for (var i = 0; i < t; i++)
{
var str1 = Console.ReadLine();
var str2 = Console.ReadLine();
var res = IsExistSubstring(str1, str2);
Console.WriteLine(res);
}
}
private static string IsExistSubstring(string str1, string str2)
{
const char start = 'a';
var abc = new bool[26];
foreach (var c in str1)
abc[c - start] = true;
return str2.Any(c => abc[c - start]) ? "YES" : "NO";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment