It turns out that I have to write a program that using a type function bool
and find()
have it return a message if s1
it is found in s2
.
The following example fails:
Failed example:
printf 'hello how are you\nbye' | ./program
Expected:
No, it does not exist
Got:
Yes, it exists
Attached the program:
#include <iostream>
#include <string>
using namespace std;
bool substringExists(string s, string subs){
if (s.find(subs)){
return true;
}else{
return false;
}
}
int main(){
string s1, s2;
cin >> s1 >> s2;
if (substringExists(s1,s2)){
cout << "Yes, it exists";
}
else{
cout << "No, it does not exist";
}
return 0;
}
It is failing you because the function
find
, in case of not findingsubs
within s, will be returning youstring::npos (-1)
Try like this: