Created
October 27, 2015 17:35
-
-
Save Baekjoon/7ad611f0c4dfe6f88017 to your computer and use it in GitHub Desktop.
brute
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> | |
#include <string> | |
using namespace std; | |
int match(string s, string p) { | |
int n = s.size(); | |
int m = p.size(); | |
for (int i=0; i<=n-m; i++) { | |
bool ok = true; | |
for (int j=0; j<m; j++) { | |
if (s[i+j] != p[j]) { | |
ok = false; | |
} | |
} | |
if (ok) return i; | |
} | |
return -1; | |
} | |
int main() { | |
string s, p; | |
s = "ABCABDABCABEABC"; | |
p = "ABCABE"; | |
//cin >> s >> p; | |
cout << match(s, p) << '\n'; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment