code is working only for n-1 testcases and i cant find any error
Replace all pi -- doubt
Hello,
If you observe the output carefully, then you would get to know that your program is running n times.
It is printing a blank line first and then n-1 test cases.
This happens when we use getline after cin.
When, cin reads the value of n, it adds a newline sequence to separate it with other inputs that would be read in future, if any.
After you do cin>>n;,
the buffer still contains the newline sequence. Then getline() reads an immediate newline(in the first iteration) which tricks it into thinking that the user just pressed enter without typing anything.
Solution:
int main()
{
int n;
cin>>n;
cin.ignore();
while(n >0)
{
string s;
getline(cin,s);
cout<<replaceallpi(s,"")<<endl;
n=n-1;
}
return 0;
}
Hope, this would help.
Give a like, if you are satisfied.
thanks…that was very helpful…