Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int t;
- cin >> t;
- while (t--) {
- string a, b;
- cin >> a >> b;
- if (a[0] == b[0]) {
- cout << "YES\n";
- cout << a[0] << "*\n";
- } else if (a[a.size() - 1] == b[b.size() - 1]) {
- cout << "YES\n";
- cout << "*" << a[a.size() - 1] << "\n";
- } else {
- bool found = false, f[26] = {0};
- for (int i = 0; i < a.size(); i++) {
- f[a[i] - 'a'] = true;
- }
- for (int i = 0; i < b.size() - 1; i++) {
- if (f[b[i] - 'a'] && f[b[i + 1] - 'a']) {
- found = true;
- cout << "YES\n";
- cout << "*" << b[i] << b[i + 1] << "*\n";
- break;
- }
- }
- if (!found) {
- cout << "NO\n";
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment