What is Difference in this two solution

This is the Question.


And i have submitted two solution for it.One is correct and another is wrong.I can’t find any difference in these solutions.Can’ You Point out What is Wrong?
Two Solutions.
https://www.codechef.com/viewsolution/27767776
https://www.codechef.com/viewsolution/27767844

Problem is because of getline. Most probably it is treating enter(after entering value of b) as string.
read this https://stackoverflow.com/questions/25475384/when-and-why-do-i-need-to-use-cin-ignore-in-c

As of my understanding there shoudn’t be any Problem because of cin.ignore() since it will ignore the ‘\n’ and the character will be assigned to string c. and we use cin.ignore() after an integer input Correct me if i am thinking wrong.

I can’t immediately think of any testcase that will cause a difference except when the second line has trailing whitespace e.g.

8
2 
/

(i’ve added a space after the 2 - hopefully the forum won’t strip it out :))

The idiomatic C++ way to skip the rest of the current line is:

cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); 

(You’ll need to

#include <limits>

for this to work).

3 Likes