Ambiguous behaviour of getline() and cin.ignore() in C++

Hey! I want an explaination for this scenario :
Problem LINK

Solution 1

Solution 2

In soltion 1 , i’m taking no. of test cases as input through cin and then ignoring the remaining line by using cin.ignore(). This results in WA.
While in Solution 2 , i’m taking the no.of test cases as input using getline and then converting it into int. This gives AC. Why is that so?? thanks in advance!

Same thing happened with me…:frowning:

Lol same thing happened with me here so I did t++ because it was working for 1 tc less :V and got AC xD

Also I tried your method here and using cin.ignore() 2 times seems to get the job done too :confused:

As observed by @ashishgup, the test cases might have extra spaces in them:

tc (space) \n