Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 25, 2016 00:10
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/ff3fd27b8c1245322adf to your computer and use it in GitHub Desktop.
Save jianminchen/ff3fd27b8c1245322adf to your computer and use it in GitHub Desktop.
Two string - C++ function template std::fill -
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int Maxn = 100005;
const int Maxl = 26;
int t;
char s[Maxn];
int slen;
bool hasa[Maxl], hasb[Maxl];
int main() {
scanf("%d", &t);
while (t--) {
fill(hasa, hasa + Maxl, false);
scanf("%s", s); slen = strlen(s);
for (int i = 0; i < slen; i++)
hasa[s[i] - 'a'] = true;
fill(hasb, hasb + Maxl, false);
scanf("%s", s); slen = strlen(s);
for (int i = 0; i < slen; i++)
hasb[s[i] - 'a'] = true;
bool has = false;
for (int i = 0; i < Maxl; i++)
has = has || hasa[i] && hasb[i];
printf("%s\n", has? "YES": "NO");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment