Created
March 19, 2016 01:38
-
-
Save jianminchen/50fc6b5a13b7d62dfa1d to your computer and use it in GitHub Desktop.
Two strings - using C#, var, foreach, Any method - interesting to read
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.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