Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 24, 2016 21:37
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/a0724f1fbbe5c621cd63 to your computer and use it in GitHub Desktop.
Save jianminchen/a0724f1fbbe5c621cd63 to your computer and use it in GitHub Desktop.
Two string - using bit operation, count, set string A char in first bit, string B char in second bit, and then, if both, then check value is 3
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
int main(){
ios::sync_with_stdio(0);
string A,B;
int T;
cin >> T;
int cont[26];
while(T--){
cin >> A >> B;
memset(cont,0,sizeof cont);
for(int i = 0;i < A.size();++i)
cont[ A[i] - 'a'] |= 1;
for(int i = 0;i < B.size();++i)
cont[ B[i] - 'a'] |= 2;
if(count(cont,cont + 26,3) > 0) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment