在本文中,我们将解决从给定字符串中删除给定单词的问题。例如 -
Input : str = “remove a given word ”, word = “ remove ” Output : “ a given word ” Input : str = “ god is everywhere ”, word = “ is ” Output : “ god everywhere ”
例如,我们可以使用一种简单的方法从字符串中删除单词。
#include <bits/stdc++.h> using namespace std; int remove_word (string str, char word[]) { char matrix[10][30]; int i = 0, j = 0, k = 0, len1 = 0, len2 = 0; // putting each word of string into the rows of the 2-D matrix. for (i = 0; str[i] != '