Skip to content

Commit

Permalink
removed unnecessary and buggy print code
Browse files Browse the repository at this point in the history
  • Loading branch information
filipemsilv4 committed Jun 1, 2023
1 parent 03c35c6 commit 9ce9761
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

Lab3/main
Lab3/main.exe
Lab4/main
Lab4/main.exe
.DS_Store
18 changes: 0 additions & 18 deletions Lab4/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ int main(void){

vector<int> positions = kmp(text, pattern);

print_text_with_highlights(text, positions, pattern.length());

// Just a nice way to print the positions
if (positions.size() == 0){
cout << "The pattern does not occur in the text." << endl;
Expand Down Expand Up @@ -97,20 +95,4 @@ vector<int> kmp(string text, string pattern){
}


void print_text_with_highlights(string text, vector<int> positions, int pattern_size){
int positions_pos = 0;
for (int i = 0; i < text.length(); i++){
// if the current index is in the positions vector, we highlight the character
if (i >= positions[positions_pos] && i < positions[positions_pos] + pattern_size){
cout << "\033[1;31m" << text[i] << "\033[0m";
if (i == positions[positions_pos] + pattern_size - 1){
positions_pos++;
}
}
else{ cout << text[i]; }
}
cout << endl;
}


// I hope it works

0 comments on commit 9ce9761

Please sign in to comment.