Created
March 24, 2016 23:25
-
-
Save jianminchen/a3865ec039c092476492 to your computer and use it in GitHub Desktop.
Two string - unordered_set, letters classes
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 <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