Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 24, 2016 22:56
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/6b443714e61f1c8c1382 to your computer and use it in GitHub Desktop.
Save jianminchen/6b443714e61f1c8c1382 to your computer and use it in GitHub Desktop.
Two string - C++ solution
#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