Two Strings

QUESTION

Given two strings, a and b, determine if they share a common substring.\n\nInput Format\n\nThe first line contains a single integer,p , denoting the number of (a,b) pairs you must check. \nEach pair is defined over two lines:\n\nThe first line contains string a.\nThe second line contains string b.\n\nConstraints\n\na and b consist of lowercase English letters only. \n\n1<=p<=10 \n 1<=|a|,|b|<=10^5\n\nOutput Format\n\nFor each (a,b) pair of strings, print YES on a new line if the two strings share a common substring; if no such common substring exists, print NO on a new line.

ANSWER

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;


int main() {
    int t;
    cin>>t;
    while(t--){
        int flag=0;
        string s,s1;
        cin>>s>>s1;
      
       for(int i=97;i<(97+25);i++)
    { char c=i;
        if( s.find(c,0)!=std::string::npos && s1.find(c,0)!=std::string::npos)
        {
            flag = 1;
            break;
        }
    }
     if(flag)  cout<<"YES";
        else cout<<"NO";
        cout<<endl;
    }
    
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.