mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-15 11:20:05 +08:00
formatting source-code for 153fb7b8a5
This commit is contained in:
@@ -17,18 +17,14 @@
|
||||
* @return Index where the pattern starts in the text
|
||||
* @return -1 if the pattern was not found.
|
||||
*/
|
||||
int brute_force(const std::string &text, const std::string &pattern)
|
||||
{
|
||||
int brute_force(const std::string &text, const std::string &pattern) {
|
||||
size_t pat_l = pattern.length();
|
||||
size_t txt_l = text.length();
|
||||
int index = -1;
|
||||
if (pat_l <= txt_l)
|
||||
{
|
||||
for (size_t i = 0; i < txt_l - pat_l + 1; i++)
|
||||
{
|
||||
if (pat_l <= txt_l) {
|
||||
for (size_t i = 0; i < txt_l - pat_l + 1; i++) {
|
||||
std::string s = text.substr(i, pat_l);
|
||||
if (s == pattern)
|
||||
{
|
||||
if (s == pattern) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
@@ -44,10 +40,8 @@ const std::vector<std::vector<std::string>> test_set = {
|
||||
{"bba", "bb", "0"}, {"bbca", "c", "2"}, {"ab", "b", "1"}};
|
||||
|
||||
/** Main function */
|
||||
int main()
|
||||
{
|
||||
for (size_t i = 0; i < test_set.size(); i++)
|
||||
{
|
||||
int main() {
|
||||
for (size_t i = 0; i < test_set.size(); i++) {
|
||||
int output = brute_force(test_set[i][0], test_set[i][1]);
|
||||
|
||||
if (std::to_string(output) == test_set[i][2])
|
||||
|
||||
Reference in New Issue
Block a user