Skip to content

Instantly share code, notes, and snippets.

@Baekjoon
Created October 27, 2015 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Baekjoon/7ad611f0c4dfe6f88017 to your computer and use it in GitHub Desktop.
Save Baekjoon/7ad611f0c4dfe6f88017 to your computer and use it in GitHub Desktop.
brute
#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