Created
March 25, 2016 00:31
Two string - C++ vector class template
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 <iostream> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
vector<int> compute_histogram(const string &s){ | |
const int n = s.size(); | |
vector<int> hist(128); | |
for(int i = 0; i < n; ++i){ ++hist[s[i]]; } | |
return hist; | |
} | |
int main(){ | |
ios_base::sync_with_stdio(false); | |
int T; | |
cin >> T; | |
while(T--){ | |
string a, b; | |
cin >> a >> b; | |
const vector<int> ha = compute_histogram(a); | |
const vector<int> hb = compute_histogram(b); | |
bool answer = false; | |
for(int i = 0; i < 128; ++i){ | |
if(ha[i] && hb[i]){ answer = true; } | |
} | |
cout << (answer ? "YES" : "NO") << endl; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment