Created
March 24, 2016 22:56
-
-
Save jianminchen/6b443714e61f1c8c1382 to your computer and use it in GitHub Desktop.
Two string - C++ solution
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 <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
#include <cstdlib> | |
#include <cstring> | |
using namespace std; | |
int T; | |
int cnt[26]; | |
string a, b; | |
int main() { | |
cin >> T; | |
while (T--) { | |
memset(cnt, 0, sizeof(cnt)); | |
cin >> a >> b; | |
for(int i = 0; i < a.length(); ++i) ++cnt[a[i] - 'a']; | |
int ans = 0; | |
for(int i = 0; i < b.length(); ++i) | |
if (cnt[b[i] - 'a'] > 0) { | |
ans = 1; | |
break; | |
} | |
if (ans == 1) cout << "YES" << endl; | |
else cout << "NO" << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment