Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 24, 2016 23:25
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/a3865ec039c092476492 to your computer and use it in GitHub Desktop.
Save jianminchen/a3865ec039c092476492 to your computer and use it in GitHub Desktop.
Two string - unordered_set, letters classes
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string>
using namespace std;
template<typename T> std::ostream& operator<<(std::ostream& str, const std::vector<T>& v) { str << "["; for(auto n : v) str << n << ", "; str << "]"; return str; }
#define debug(x) cout << #x << ": " << x << endl
int main() {
cin.sync_with_stdio(false);
cout.sync_with_stdio(false);
int t;
cin >> t;
while(t--) {
string s1, s2;
cin >> s1 >> s2;
unordered_set<char> letters;
letters.reserve(s1.size());
for(auto c : s1) letters.insert(c);
for(auto c : s2) if(letters.count(c)) {
cout << "YES\n";
goto next;
}
cout << "NO\n";
next:
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment