Given a string, check if it contains the word “not” as a complete word. (Not as a part of another word, like nothing)
SUPER QUICK EXPLANATION
The quote is Real Fancy, if the quote is “not”, quote begin with “not*”, quote ends with “not" or quote contains “not” where "” represents space character.
EXPLANATION
Consider the special case where quote itself is “not” separately.
After this, the word “not” can either appear as the prefix, as the suffix or in between the quote. So, check separately if the first word is “not”, the last word is “not” or the quote contains the word “not”. (Make sure to check that the word “not” is surrounded by space character on both sides.)
Trick
Those not interested in splitting the string into words can solve this by inputting the quote as a string, add space character at both ends of strings. Now, the quote will be “Real Fancy” if it contains “not” where “*” represents space character.
As a side fact, @vijju123 actually have a thing about fancy quotes. He has another fancy quote, shared during the contest, “You made my non-fancy quote a fancy one”.
Time Complexity
Time complexity is O(|S|) per test case where |S| is the length of the quote.
contains "not" where "*" represents space character.
Which *?
Consider the special case where quote itself is "not" separately.
After this, the word "not" can either appear as the prefix, as the suffix or in between the quote. So, check separately if the first word is "not", the last word is "not" or the quote contains the word "not". (Make sure to check that the word "not" is surrounded by space character on both sides.)
Wait, is the solution not just taking entire line as input and checking if 3 consecutive words are no and t ? Is it wrong? If no then whats this story about. This editorial is scaring me… so scary
“You made my non-fancy quote a fancy one.” xD
Feb challenge is around the corner …
P.S. - See excitement of @vijju123 he posted the same answer thrice. (I hope everyone knows the context )
I used the concept of word boundaries using regex which reduced my code to just one if statement. No breaking of the string, nothing. I feel this might be helpful. @taran_1407 what do you think about it?
I have also done using Tokenize method but fail because of irrelevant behaviour of c++. I see that @tester and @I_return use the getline(cin,s) before the while() loop. What is that for? Anyone help.