FANCY - EDITORIAL

cakewalk
fancy
jan19
taran_1407

#1

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2

Setter: Shivam Gupta
Tester: Xiuhan Wang
Editorialist: Taranpreet Singh

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

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.

AUTHOR’S AND TESTER’S SOLUTIONS:

Setter’s solution
Tester’s solution
Editorialist’s solution

Feel free to Share your approach, If it differs. Suggestions are always welcomed. :slight_smile:


#2

@admin Access denied to solutions!! Please fix it.


#3

##My solution has no corner cases…

Most easiest way according to me is to tokenize(break) string with spaces…

#Here is my solution…


#4

contains "not" where "*" represents space character.

Which *? :stuck_out_tongue:

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 n o and t ? Is it wrong? If no then whats this story about. This editorial is scaring me… so scary :frowning:

(I hope everyone knows the context :stuck_out_tongue: )


#5

“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 :stuck_out_tongue: )


#6

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?

My Solution


Click here to know more about word boundaries.


#7

I used simple regex pattern in java :-

"\\bnot\\b"

and check whether it is present or not.

\\b

is for the word boundries, to handle cases where not can be present in the word itself. Full solution link

Solution


#8

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.


#9

@yash005 they are reading the number of test-cases also as a string which help(s) a lot!:slight_smile:


#10

https://www.codechef.com/viewsolution/22435475

what is the error in it?all test cases pass easily.please help. :expressionless:


#11

@karangreat234, they aren’t reading, actual reading is inside the while loop. Can anyone help me figure out @tester and @I_return use the getline(cin,s) before the while() loop.


#12

Plz. Help me why my code gives wrong result.
Is this approach is wrong.
https://www.codechef.com/viewsolution/22697199

https://www.codechef.com/viewsolution/22697199


#13

Getting NZEC.
I’m using Python3 and using input() to read inputs.
Surfed to get the fix of this issue, hence i’m here.

This is how i’m reading inputs.

t = int(input())
for item in range(t):
    s = input().split()

Anyone ???


#14

Hi,
my method looks similar to the one mentioned in the editorial. But it’s giving ‘WA’. Can you guys please point out the reason. Thanks.
Please find the link to my submission [here][1].
[1]: https://www.codechef.com/viewsolution/23603588


#15

Wut? ._. ??


#16

Used python to do this :P.


#17

Its not called excitement, its called 504 Bad Gateway when submitting answers xD


#18

I also used regex, but in Perl 6, it could be reduced to a one-liner:

for ^get() { put /<<not>>/ ?? 'Real Fancy' !! 'regularly fancy' for get }

#19

Yes, your solution is wrong. Your solution fails on the test “nothing is wrong”.

I hope you found editorial not only scary, but helpful :slight_smile:


#20

Even Discuss knows about your excitement xD