WA Because Of Fastscan()

Link to Question : Programming Problems and Competitions :: HackerRank

Link to Answer getting WA : RRSIWD - Online C++ Compiler & Debugging Tool - Ideone.com

Link to Answer getting AC : FEq5ut - Online C++ Compiler & Debugging Tool - Ideone.com

Just removing Fastscan() Gives AC .

Can’t Figure out Why???

Your fastscan() function is not entirely correct. It will not behave in the expected manner if there are more than two junk characters (not a digit or "-") between 2 integers, such as a line ending with "\r\n" instead of "\n". You could change it to something like this which assumes all characters less than ASCII 48, which includes common whitespace characters, are junk and skips over them.

void fastscan(ll &x) {
    ...
    x = 0;
    while((c=getchar()) < 48);
    if(c == '-') {
        ....
    }
    ....
}
2 Likes

Yeah!! It worked !!
Thanks!!