Created
March 25, 2016 00:47
-
-
Save jianminchen/43f23e82ee04076c7496 to your computer and use it in GitHub Desktop.
Two string - C++ - code is very readable -
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 <string> | |
#include <cstring> | |
using namespace std; | |
const int MAXN = 128; | |
int count1[MAXN], count2[MAXN]; | |
string s1, s2; | |
void getCount(string s, int arr[]) { | |
for (int i = 0; i < s.length(); i++) { | |
arr[s[i]]++; | |
} | |
} | |
bool hasCommon() { | |
for (int i = 'a'; i <= 'z'; i++) { | |
if (count1[i] && count2[i]) { | |
return true; | |
} | |
} | |
return false; | |
} | |
int main() { | |
int nCases; | |
cin >> nCases; | |
while (nCases--) { | |
memset(count1, 0, sizeof(count1)); | |
memset(count2, 0, sizeof(count2)); | |
cin >> s1 >> s2; | |
getCount(s1, count1); | |
getCount(s2, count2); | |
if (hasCommon()) { | |
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