C/C++ C++: Word Censor - Print "Censored

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
AI Thread Summary
The discussion centers on a programming challenge that requires printing "Censored" if a user input string contains the word "darn"; otherwise, it should print the original input. Participants express confusion about how to implement this functionality, particularly regarding string manipulation and substring searching. Suggestions include using standard functions like find() and substr(), but there is a debate about whether these should be utilized or if a manual approach is necessary. The conversation emphasizes the need to understand how to enumerate substrings and check for matches, with hints pointing towards algorithms for substring detection. Participants also express frustration over a lack of instructional resources in their course, highlighting difficulties in grasping the concepts needed to solve the problem effectively.
ineedhelpnow
Messages
649
Reaction score
0
Print "Censored" if user text contains the word "darn", else print userInput. end with new line.

Sample program:

Code:
#include 
#include  
using namespace std;

int main() {
   string userInput;

   userInput = "That darn cat.";
   <student code>
    

   return 0;
}

I'm super lost on this. I could definitely use some help/hints. Thanks.
 
Technology news on Phys.org
Read the "Searching and Substrings" section of this page, or, better, read your textbook or lecture notes.
 
we don't have a textbook for the class. he doesn't give us anything to take notes on.
 
ineedhelpnow said:
he doesn't give us anything to take notes on.
Aren't you supposed to bring your own notebooks? Anyway, if you have questions after reading the web page linked above, let us know.
 
lol i meant in his lecture there is nothing useful for us to record down. he goes over the homework and he'll be like ok do this problem and then do this oh and don't do this lesson. and then he'll just talk at as about computer science or computer engineering.
 
So the string contains the word "darn" if and only if the string contains a substring of length 4 equal to "darn". How would you enumerate all substrings of length 4 in a string? How would you check if they are equal to "darn"?

I'm assuming you need to do it manually here, since there are standard functions for doing this sort of thing already.
 
:o I am still stuck on this problem. i really don't understand it all. can someone tell me what command i need to use at least. i might be able to figure the rest out. like do i use: find(), substr()?
 
It is easier to use the function [m]find()[/m] described in the link I gave in post #2. Then checking whether the string is censored is a one-liner. If you were said not to use standard functions, then we need to come up with an algorithm that checks for occurrence of a substring. In that case, you can pretend you have a sequence of letter blocks. Describe how you would check them one at a time (this is important) to find a substring.
 

Similar threads

Replies
2
Views
5K
Replies
4
Views
6K
Replies
14
Views
34K
Replies
1
Views
5K
Replies
40
Views
3K
Replies
22
Views
3K
Back
Top