Untitled

 avatar
unknown
plain_text
4 years ago
473 B
5
Indexable
#include <iostream>

using namespace std;
int findInString(const string &s, const string &toFind){
int m = s.length();
int n = toFind.length();
if (n>m){
return -1;
}
for (int i = 0; i <= (m-n); i++){
int j;
for (j=0; j<n; j++){
if(s[i+j]!=toFind[j]){
break;
}
}
if (j==n){
return i;
}
}
return -1;
}

int main()
{
string s,toFind;
cout << "s = " << endl;
getline(cin, s);
cout << "To Find : " << endl;
getline(cin, toFind);
int ans = findInString(s,toFind);
cout << ans;
}
Editor is loading...