You are not logged in. Please login at www.codechef.com to post your questions!

×

FANCY - EDITORIAL

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. :)

This question is marked "community wiki".

asked 14 Jan, 15:54

taran_1407's gravatar image

6★taran_1407
3.9k2892
accept rate: 22%

edited 14 Jan, 19:35

admin's gravatar image

0★admin ♦♦
19.8k350498541

1
(15 Jan, 23:12) shivam_g14704★

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

link

answered 14 Jan, 19:59

magic105's gravatar image

2★magic105
0
accept rate: 0%

My solution has no corner cases...

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

Here is my solution...

link

answered 14 Jan, 22:22

l_returns's gravatar image

5★l_returns
1.4k19
accept rate: 25%

1

Used python to do this :P.

(15 Jan, 00:50) aryanc4036★

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

Which *? :p

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 :(

(I hope everyone knows the context :p )

link

answered 15 Jan, 00:24

vijju123's gravatar image

5★vijju123 ♦♦
15.4k12066
accept rate: 18%

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

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

(15 Jan, 12:23) taran_14076★

Thats even more scary :(

(15 Jan, 15:08) vijju123 ♦♦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 :p )

link

answered 15 Jan, 00:45

aryanc403's gravatar image

6★aryanc403
2.5k1516
accept rate: 10%

edited 15 Jan, 00:51

Wut? ._. ??

(15 Jan, 00:50) vijju123 ♦♦5★

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

(15 Jan, 00:53) vijju123 ♦♦5★

Even Discuss knows about your excitement xD

(15 Jan, 12:24) taran_14076★

Even discuss got scared by your editorial~~~

(15 Jan, 15:08) vijju123 ♦♦5★

I hope everyone knows the context :p

(15 Jan, 15:23) aryanc4036★

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.

link
This answer is marked "community wiki".

answered 15 Jan, 01:36

dipanshu_10297's gravatar image

4★dipanshu_10297
01
accept rate: 0%

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 }
(15 Jan, 08:52) mcsinyx2★

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

link

answered 15 Jan, 16:16

brij_raj's gravatar image

2★brij_raj
756
accept rate: 14%

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.

link

answered 16 Jan, 16:21

yash005's gravatar image

1★yash005
01
accept rate: 0%

Answer is hidden as author is suspended. Click here to view.

answered 16 Jan, 17:10

karangreat234's gravatar image

4★karangreat234
(suspended)
accept rate: 0%

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

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

link

answered 17 Jan, 19:58

rahil_1407's gravatar image

2★rahil_1407
1
accept rate: 0%

ACed Solution: https://www.codechef.com/viewsolution/22520214 You should print exactly as specified

(17 Jan, 22:00) shivam_g14704★

@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.

link

answered 17 Jan, 22:47

yash005's gravatar image

1★yash005
01
accept rate: 0%

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

link
This answer is marked "community wiki".

answered 30 Jan, 19:24

masterpranay's gravatar image

2★masterpranay
1
accept rate: 0%

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 ???

link

answered 09 Feb, 20:07

a874's gravatar image

0★a874
1
accept rate: 0%

I could not find your submission but here is my submission i made using above mentioned code. I think you might be trying on codechef ide and not giving any custom input and NZEC is due to no data in stdin.

(09 Feb, 22:03) shivam_g14704★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,652
×649
×109
×10

question asked: 14 Jan, 15:54

question was seen: 2,053 times

last updated: 09 Feb, 22:03