NOLOGIC - Editorial

#include
#include
#include
using namespace std;
int main()
{
int t;
char question[320];
bool x[26]={false};
int i;
scanf("%d",&t);
while(t–)
{
gets(question);
for(i=0;i<(int)strlen(question);++i)
{
if(isalpha(question[i]))
{
if(islower(question[i]))
x[question[i]-97]=true;
else
x[question[i]-65]=true;
}
}
bool flag=true;
for(i=0;i<26;++i)
{
if(x[i]==false)
{
printf("%c\n",i+65);
flag=false;
break;
}
}
if(flag) printf("~\n");
}
return 0;
}

I don’t know why this code is not working can any one tell why?

1 Like

@amitupadhyay
Your solution has several mistakes.

  1. You should read a new-line character after scanf("%d",&t) as explained in the editorial.
  2. Declaration of bool x[26]={false}; should be moved inside while-loop.

By simply fixing this I’ve got AC:
http://www.codechef.com/viewsolution/1853065

But your code also has another bad place.
You calculate strlen(question) each time in the loop.
Note that strlen() function works in O(N) time.
So your solution is actually has complexity O(N * N).
If constraints would be higher (like question length up to 31415) you would probably get TLE.
It is always better to save the length at some variable like int this fix of your solution:
http://www.codechef.com/viewsolution/1853057

3 Likes

it might be the dumb question but i want to know what’s wrong in writing if(‘a’ <= s[i] <= ‘z’) (than if(‘a’ <= s[i] && s[i] <= ‘z’)) in c? I am getting wrong answer for first case.

@anton_lunyov i have been using scanf("%d\n",&t) blindly without knowing how it is working.
“The \n format will skip all whitespaces until it finds a non-whitespace character” . why does it skips?

also please explain %d%*c format. what is %*c doing ?

can anybody plz help me with my code…
its giving WA…and i m unable to figure it out…
here is my code
CodeChef: Practical coding for everyone

can anyone tell me what is wrong with my code? I feel that my program is exactly according to the editorial, but it still gives me WA.
http://www.codechef.com/viewsolution/1861051

Why is this problem only available in 3 languages?

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

read the editorial i still didnt get it!

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?

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: