Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 24, 2016 17:35
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/13c2d3832f1cbd53433c to your computer and use it in GitHub Desktop.
Save jianminchen/13c2d3832f1cbd53433c to your computer and use it in GitHub Desktop.
Two string - C++ solution - memset, for loop, type conversion a[i] - 'a', and break statement
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
using namespace std;
int m[27];
int t;
string a;
string b;
int main(){
cin >> t;
while (t--){
cin >> a >> b;
for (int i = 0; i < a.size(); i++){
m[a[i] - 'a']++;
}
bool ok = 0;
for (int i = 0; i < b.size(); i++){
if (m[b[i] - 'a']){
ok = 1;
break;
}
}
if (ok){
puts("YES");
}
else{
puts("NO");
}
memset(m, 0, sizeof(m));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment