Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 19, 2016 06:30
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/1fcc46803321f007eb1b to your computer and use it in GitHub Desktop.
Save jianminchen/1fcc46803321f007eb1b to your computer and use it in GitHub Desktop.
Two String - use StringBuilder for output of console - look into StringBuilder vs string for concatenation
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
class Solution {
static void Main(String[] args) {
int t = Convert.ToInt32(Console.ReadLine());
StringBuilder sb = new StringBuilder();
for(int i = 0; i < t; i++){
bool[] chars = new bool[26];
string str1 = Console.ReadLine();
foreach(char c in str1.ToCharArray()){
chars[c-'a'] = true;
}
string str2 = Console.ReadLine();
bool found = false;
foreach(char c in str2.ToCharArray()){
if (chars[c-'a']){
sb.AppendLine("YES");
found = true;
break;
}
}
if (!found){
sb.AppendLine("NO");
}
}
Console.WriteLine(sb.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment