Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 25, 2016 00:31
Show Gist options
  • Save jianminchen/c0e3a44edc31b3804331 to your computer and use it in GitHub Desktop.
Save jianminchen/c0e3a44edc31b3804331 to your computer and use it in GitHub Desktop.
Two string - C++ vector class template
#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