Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 19, 2016 01:58

Revisions

  1. jianminchen created this gist Mar 19, 2016.
    33 changes: 33 additions & 0 deletions TwoString10.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    using System;
    using System.Collections.Generic;
    using System.IO;
    class Solution {
    static void Main(String[] args) {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
    int T = int.Parse(Console.ReadLine());
    for(int i=0; i<T; i++){
    String A = Console.ReadLine();
    String B = Console.ReadLine();
    Boolean flag = false;
    char [] a = A.ToCharArray();
    Array.Sort(a);
    char [] b = B.ToCharArray();
    Array.Sort(b);
    int j=0,k=0;
    while(j<a.Length && k<b.Length){
    if(a[j]==b[k]){
    flag = true;
    break;
    }
    else if(a[j]<b[k])
    j++;
    else
    k++;
    }
    if(flag)
    Console.WriteLine("YES");
    else
    Console.WriteLine("NO");
    }
    }
    }