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
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.
Expression ('a' <= s[i] <= 'z') is equivalent to ('a' <= s[i]) <= 'z'.
So it compares bool value ('a' <= s[i]) with char value 'z'.
Hence, it casts both values to int: 'z' to 122 and ('a' <= s[i]) to 0 if it is false or to 1 if it is true.
So ('a' <= s[i] <= 'z') is always true
@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 ?
@aichemzee: your code simply contains T+1 x \n and as stated in statement
Special judge is very strict for this problem and check your output character-by-character. Be sure that you follow the mentioned output format precisely. For instance, your output should contain exactly T new-line characters (ASCII code 10) - one after each answer.
@anton_lunyov thanks for such problem, I hope a lot of coders learnt lesson in this contest
If it’s specified in statement so precisely as in this I think it is perfectly fine to reject such submissions.
On the other hand I prefer no so strict judge, for example if one have to print N numbers in line, typically it’s ok when there is space after the last one or so, because one can use FOR(i,0,N) printf("%d ", a[i]) instead of printf("%d", a[0]); FOR(i,1,N) printf(" %d", a[i]) and AFAIK in ACM contest there is special judgement result “wrong format” that is shown sometime in such cases…
@betlista As I said above try to solve something on UVA.
After struggling to solve some simple problem you will reconsider your opinion
To output N space separated integers you could use code FOR(i,0,N) printf("%d%c", a[i], i<N-1?' ':'\n')
So nothing ugly.
@aichemzee Usually special judge at codechef ignores extra white spaces.
So not need to worry about that in the future.
Actually both ways with scanf("%d%*c") and with getchar() do not handle the case with '\r\n'.
So the most general way is to use gets() or do getchar() / scanf("%c") in a loop.
@anton_lunyov: thanks for your tip, good point I just said I prefer no so strict judge, but I’m always sticking with format specified in statement, because I never know if the judge is or is not strict