Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 24, 2016 23:20
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/f4b6dcea9936347192e9 to your computer and use it in GitHub Desktop.
Save jianminchen/f4b6dcea9936347192e9 to your computer and use it in GitHub Desktop.
Two string - C++ if(a[i] && b[i]) statement
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include<string>
#include <algorithm>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int a[101]={0},b[101]={0};
string s1,s2;
cin>>s1>>s2;
for(int i=0;i<s1.length();i++)
a[s1[i]-'a']++;
for(int i=0;i<s2.length();i++)
b[s2[i]-'a']++;
int flag=0;
for(int i=0;i<26;i++)
{
if(a[i] && b[i])
flag=1;
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment