Created
April 24, 2018 15:00
-
-
Save ouwenshi/b07bb112a5ab4130846388b263278aa7 to your computer and use it in GitHub Desktop.
Find a string S in a given given string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int findSubString(string s, string sub, const string &S, int pos, int cur) { | |
| if (sub.empty()) | |
| return pos; | |
| else if (s.empty()) | |
| return -1; | |
| if (s[0] == sub[0]) | |
| return findSubString(s.substr(1), sub.substr(1), S, pos, cur + 1); | |
| else | |
| return findSubString(s.substr(1), S, S, cur + 1, cur + 1); | |
| } | |
| void main() { | |
| string S = "myword"; | |
| cout << findSubString("hereis mywor dwow mywordhaha.", S, S, 0, 0) << endl; | |
| //cout << findSubString("hereis mywor dwow mywo rdhaha.", S, S, 0, 0) << endl; | |
| cin.get(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment