if i am writting stdin.readline()[:-1]
then i’m getting wrong ans on same logic , and on writting stdin.readline() OR input() Gives correct answer
It’d be a lot more convenient if you actually paste those submission links; my brain is not a compiler please and thanks
When you test on CodeChef IDE does it get the sample right?
Because fast input is can not read by the compiler
actually there are alot number of submissions made by me
so here is one of them.
What is the [:-1]
for? The integer parser will automatically ignore the \n
.
yes sir it is for string input
actually this is not the first time i’m using system module but i don’t know why from past 2,3 days i’m facing this problem.
But why do you ignore the last character?
def si():return stdin.readline()[:-1]
In, int_input=int(si()) -> int function automatically deletes the \n so it doesn’t affect either to perform slicing here or not
but in,
str_input=si() i’ve to do slicing (deleting the last charaxter manually) otherwise my string will have extra character \n which will create chaos(BT)
for past two months i’ve been doing it,but yesterday and today it is giving me tough time
so I’m just asking while performing slicing it is giving me wrong answer which it shouldn;t bcoz int() can handle endline character on its own
I’m not sure if CodeChef uses any sort of validators on inputs, so it’s possible that inputs may (inconsistently) not have a newline on the last line. You can get around that by explicitly checking if the last character is equal to \n
.
In theory, yes (for its “official” Contests), and I believe "last line ends with \n
" is part of the check, but in practice, Problems occasionally slip through the cracks and don’t get validated in this way.
External contests are a whole different ballgame, though, and frequently have inconsistent whitespace.