Doubt in Replace pie

In this question when pie is getting replaced by 3.14, then after 3.14 it is giving some garbage value.
Here is the code given below.

Hello @ratulhans,

There are three issues with your code:

  1. Incomplete Output:
    Example:
    1
    xpipipxpixx
    Your Output:
    x3.14
    Expected Output:
    x3.143.14px3.14xx
    Solution:
  else{
    b[j]=a[i];
    j=j+1;
    i=i+1;
  }

You are missing braces, which causes unwanted increment in i and j.
Thus, causing wrong output.

  1. It will fail for longer strings:
    It is mentioned in the code, 0 <= len(str) < 1000
    Also, for every “pi” two extra characters are added “3.14”
    Problem:
    char a[100],b[100];
    Solution:
    char a[1000],b[3000];

  2. When you take input using cin, the compiler adds “/n” i.e. endline corrector in the input stream.
    And after reading input from stream, it does not removes “/n” from the stream.
    Thus, when you would use cin.getline() function:
    It will first read “/n”, causing a blank line in the output.

I have modified your Code:

Give a like, if you are satisfied.