Created
March 24, 2016 21:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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