Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 19, 2016 01:36
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/cece566bd69963533e80 to your computer and use it in GitHub Desktop.
Save jianminchen/cece566bd69963533e80 to your computer and use it in GitHub Desktop.
Two strings - using string.intersect method
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution
{
static void Main(String[] args)
{
IoHelper.SetConsoleBufferSize((sizeof(char) * 100000) + 100);
List<string> results = new List<string>();
int t = IoHelper.ReadInt();
for (int i = 0; i < t; i++)
{
string a = Console.ReadLine();
string b = Console.ReadLine();
string result = "NO";
if (a.Intersect(b).Any())
{
result = "YES";
}
results.Add(result);
}
results.ForEach(Console.WriteLine);
}
public class IoHelper
{
public static void SetConsoleBufferSize(int size)
{
byte[] inputBuffer = new byte[size];
Stream inputStream = Console.OpenStandardInput(inputBuffer.Length);
Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length));
}
public static int ReadInt()
{
int n;
int.TryParse(Console.ReadLine(), out n);
return n;
}
public static int[] ReadIntArray(char separator = ' ')
{
return Console.ReadLine().Trim().Split(separator).Select(n => int.Parse(n)).ToArray();
}
public static uint ReadUInt()
{
uint n;
uint.TryParse(Console.ReadLine(), out n);
return n;
}
public static uint[] ReadUIntArray(char separator = ' ')
{
return Console.ReadLine().Trim().Split(separator).Select(n => uint.Parse(n)).ToArray();
}
public static long ReadLong()
{
long n;
long.TryParse(Console.ReadLine(), out n);
return n;
}
public static long[] ReadLongArray(char separator = ' ')
{
return Console.ReadLine().Trim().Split(separator).Select(n => long.Parse(n)).ToArray();
}
public static ulong ReadULong()
{
ulong n;
ulong.TryParse(Console.ReadLine(), out n);
return n;
}
public static ulong[] ReadULongArray(char separator = ' ')
{
return Console.ReadLine().Trim().Split(separator).Select(n => ulong.Parse(n)).ToArray();
}
public static double ReadDouble()
{
double n;
double.TryParse(Console.ReadLine(), out n);
return n;
}
public static double[] ReadDoubleArray(char separator = ' ')
{
return Console.ReadLine().Trim().Split(separator).Select(n => double.Parse(n)).ToArray();
}
}
public class MathHelper
{
public static long GCD(long[] numbers)
{
return numbers.Aggregate(GCD);
}
public static int GCD(int[] numbers)
{
return numbers.Aggregate(GCD);
}
public static long GCD(long a, long b)
{
return b == 0 ? a : GCD(b, a % b);
}
public static int GCD(int a, int b)
{
return b == 0 ? a : GCD(b, a % b);
}
public static long LCM(long a, long b)
{
return (a * b) / GCD(a, b);
}
public static int LCM(int a, int b)
{
return (a * b) / GCD(a, b);
}
public static List<int> GetPrimeNos(int upto)
{
int primeNosLimit = upto;
List<int> primeNos = new List<int>();
primeNos.Add(2);
primeNos.Add(3);
int pp = 3;
bool test = true;
double sqrtpp;
while (pp < primeNosLimit)
{
pp += 2;
test = true;
sqrtpp = Math.Sqrt(pp);
for (int i = 0; i < primeNos.Count; i++)
{
int a = primeNos[i];
if (a > sqrtpp) break;
if (pp % a == 0)
{
test = false;
break;
}
}
if (test)
{
primeNos.Add(pp);
}
}
return primeNos;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment