solved hackerrank.two.strings

Signed-off-by: ayham <altffour@protonmail.com>
This commit is contained in:
ayham 2021-05-13 12:13:46 +03:00
parent f39777f6a2
commit 44bee6e8f3
No known key found for this signature in database
GPG Key ID: 81D38F7122AFCC94
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int p;
string a, b;
cin >> p;
while (p--) {
bool has_substring = false;
map<char, int> repeats;
cin >> a >> b;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
auto a_last = unique(a.begin(), a.end());
a.resize(distance(a.begin(), a_last));
auto b_last = unique(b.begin(), b.end());
b.resize(distance(b.begin(), b_last));
for (auto i : a) {
if (repeats.find(i) == repeats.end()) repeats[i] = 1;
else repeats[i]++;
}
for (auto i : b) {
if (repeats.find(i) == repeats.end()) repeats[i] = 1;
else repeats[i]++;
}
for (auto it : repeats) {
if (it.second > 1) {
has_substring = true;
break;
}
}
cout << ((has_substring) ? "YES" : "NO") << endl;
}
return 0;
}