NOLOGIC - Editorial

PROBLEM LINKS

Practice

Contest

DIFFICULTY

CAKEWALK

PREREQUISITES

Ad Hoc

PROBLEM

We are given several questions. Answer each question such that the answer has no logic, i.e. has no common letters with the corresponding question.

QUICK EXPLANATION

Iterate over all allowed letters. For each letter, check whether it is present in the question. If it is not, then a string consisting of the letter is valid as an answer to the question. If all possible letters are present, then there is no possible answer.

EXPLANATION

There are many ways to solve this problem. However, since this problem appears in a cook-off contest, we obviously want the simplest solution that just works. Here we will present such solution.

The problem asks for an answer (a string) that has no common letters with the corresponding question. Therefore, the simplest answer is just a letter that is not present in the question. We can iterate the letters in the question and mark them as “used”, and then iterate all allowed letters and print one that is not marked as “used”. If all allowed letters are “used”, then there is no answer to the question.

Here is the pseudocode that produces the answer for each question. Note that we have to be aware that lowercase and uppercase letters should be considered equal.

for i := 0 to length(question) - 1:
    used[question[i]] = true

found := false
for i := 0 to 25:
    if not used['a' + i] and not used['A' + i]:
        found := true
        println('a' + i)
        break
    if not found:
        println('~')

NOTES TO C/C++ USERS

This applies to those that use I/O functions in <stdio.h>. Since each question can contain spaces, we can use gets() to read the question. A very common way to do this is as follows:

scanf("%d\n", &T);
for (int tc = 0; tc < T; tc++) {
    gets(question);
}

Here we use “%d\n” format to read the number of test cases and the following new line. This is wrong if the first test case only consists of spaces! The “\n” format will skip all whitespaces until it finds a non-whitespace character. Therefore, the first test case will not be read at all.

The correct way is to use “d*c” format to skip exactly one character (i.e. ‘\n’), or

scanf("%d", &T);
gets(question);
for (int tc = 0; tc < T; tc++) {
    gets(question);
}

SETTER’S SOLUTION

Can be found here.

TESTER’S SOLUTION

Can be found here.

4 Likes

and the judge wasn’t accepting my solution if it had two newlines at the last test case.
took me 3 WA to figure out ##### sigh###

What’s problem in this code. Its getting WA.
ideone link

The note in the problem statement clearly indicates that the number of new-lines should be exactly T. Additional new line in the end violates this rule so no wonder :slight_smile:

1 Like

@prakhs123 @vinoth03
Common guys! Try to read editorial at least by one eye :slight_smile:

3 Likes

read the editorial i still didnt get it!

Here we use “%d\n” format to read the number of test cases and the following new line. This is wrong if the first test case only consists of spaces! The “\n” format will skip all whitespaces until it finds a non-whitespace character. Therefore, the first test case will not be read at all.

The correct way is to use “d*c” format to skip exactly one character (i.e. ‘\n’)

Very well explained. Caused me 5 WA, but lesson learnt :slight_smile:

1 Like

That was one of the insights behind the problem to teach this lesson :slight_smile:

4 Likes

The problem exists in line scanf("%d\n", &T);. Please read the editorial explaining the problem with using format specifier “%d\n”.

1 Like

sorry !!!

Do we need to print the all letters those are not in the question
or Simply one of them will work?

http://www.codechef.com/viewsolution/1851711 please check my code

Guys! Why you all even not try to look through the editorial?
Did you see section “NOTES TO C/C++ USERS” there?

2 Likes

this was never a concern untill today. I mean I always appended ans+"\n" and in the end used System.out.println() which caused an additional newline. And yes, i saw that T newline thing, and used the .print() instead. And bingo AC. Still, this kindov thing was rather lame. Gave me 3 WA’s.

Simply one of them will work too.

And i thought codechef was at fault for not accepting my solution.Quite an easy problem with a twisting catch.Well set Admin.

OK. Next time I will try to write kinder judge from this perspective. At least existing special judge was easy to code. While allowing all possible new-lines features that contestants are used to is not so trivial to figured it out.

Try to solve something on UVA. They have very strict judge as well but no for all problems.

I meant it shouldn’t matter whatever i print after the T required output lines. Ideally those shouldn’t be processed. And statistically that should make the judge more efficient :stuck_out_tongue:

we can also use a getchar() after the scanf("%d",&t) to read the enter pressed.

“Ideally those shouldn’t be processed.” It is completely wrong. The judge should validate the full conformation of the answer to the output format. If for example in the challenge problem you need to print N followed by N lines describing some operations but you print N+1 lines with operation on the last line then it is wrong and actually AC could only make you worse since you may get low score while thinking that all is right with the solution.

//