Replace of π: I guess my logic is correct,still failing

Please review my code. It’s working on custom input.
But failing the test cases.

Plz send your code by saving on ide only

Sorry ma’am just forgot to attach the link.
Link : https://ide.geeksforgeeks.org/XZWEuhcKvV

In your code, getline() is not reading the string.

The reason for this behavior is,
If getline is used after “cin >>” statement, the getline() sees this newline character as leading whitespace, and it just stops reading any further.

This leading whitespace is added to mark the end of line.

When you do cin >> n;, that gets the value of n from the input stream, but it leaves whitespace on the stream. Specifically, it will leave a newline on the input stream, which then gets read by the next getline call as an empty line.
hence, ignoring the actual string.

solution:
Call cin.ignore() before calling getline()

syntax:
istream& ignore (streamsize n = 1, int delim = EOF);
where,
n is the number of characters you wants to discard, and
delim is the delimiter.

It basically, extracts characters from the input sequence and discards them, until either n characters have been extracted, or one compares equal to delim.
thye default value is 1 character.

NOTE:
If you’ll use this statement inside the loop. It will discard the first character of each input.
Thus, write it outside the loop after cin >> statement.

I would to try it yourself, and observe the outputs it produce.

Hope, this would help.
Give a like if you are satisfied.

Again great explanation. Thanks sir. Learnt something new today. :slight_smile: