Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 29, 2021 14:19
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 codecademydev/4f3d133b1def08570e0e67c4e1d80dd8 to your computer and use it in GitHub Desktop.
Save codecademydev/4f3d133b1def08570e0e67c4e1d80dd8 to your computer and use it in GitHub Desktop.
Codecademy export
#include <iostream>
#include <string>
#include "functions.hpp"
int main(){
std::string word = "broccoli";
std::string text = "Broccoli is my favoriate vegetable,broccoli tastes good.";
bleep(word, text);
std::cout << text;
}
#include <iostream>
#include <string>
void subs(std::string const &key_word, std::string &tar_text, int start) {
for (int i = 0; i < key_word.size(); i++ ) {
tar_text[start + i] = '*';
}
}
void bleep(std::string const &key_word, std::string &tar_text) {
for (int i = 0; i < tar_text.size() - key_word.size(); i++) {
int match = 0;
if (tar_text[i] == 'b') {
for (int j = 0; j < key_word.size(); j++) {
if (tar_text[i+j] == key_word[j]) {
match++;
}
}
if(match == key_word.size()) {
subs(key_word, tar_text, i );
}
}
}
}
#include <iostream>
#include <string>
void bleep(std::string &key_word, std::string &tar_text);
void subs(std::string const &key_word, std::string &tar_text, int start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment