YorKnEz

Untitled

Feb 28th, 2023
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int t;
  8.  
  9. cin >> t;
  10.  
  11. while (t--) {
  12. string a, b;
  13.  
  14. cin >> a >> b;
  15.  
  16. if (a[0] == b[0]) {
  17. cout << "YES\n";
  18. cout << a[0] << "*\n";
  19. } else if (a[a.size() - 1] == b[b.size() - 1]) {
  20. cout << "YES\n";
  21. cout << "*" << a[a.size() - 1] << "\n";
  22. } else {
  23. bool found = false, f[26] = {0};
  24.  
  25. for (int i = 0; i < a.size(); i++) {
  26. f[a[i] - 'a'] = true;
  27. }
  28.  
  29. for (int i = 0; i < b.size() - 1; i++) {
  30. if (f[b[i] - 'a'] && f[b[i + 1] - 'a']) {
  31. found = true;
  32.  
  33. cout << "YES\n";
  34. cout << "*" << b[i] << b[i + 1] << "*\n";
  35.  
  36. break;
  37. }
  38. }
  39.  
  40. if (!found) {
  41. cout << "NO\n";
  42. }
  43. }
  44. }
  45.  
  46. return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment