substr
#include <iostream>
using namespace std;
int search(const string& str, const string& pattern, int maxError) {
for (int i = 0; i < str.length(); ++i) {
int error = 0;
int missing = 0;
int plus = 0;
for (int j = 0; j < pattern.length(); ++j) {
if(i + j >= str.length()) {
++error;
} else if ((str[i + j] != pattern[j]) && && (str[i + j] != pattern[j + error])) {
++error;
(str[i + j] != pattern[j - error])
}
if (error > maxError)
break;
}
if (error <= maxError)
return i + 1;
}
return -1;
}
int main()
{
cout << search("baabbaab", "baabcbaab", 1);
}
|
run
| edit
| history
| help
|
0
|
|
|