My code is merging answers

#include
#include
using namespace std;
int k=0;
char n[10000];
void pi(char s[],int l,int i)
{
char p[10000]=β€œ3.14”;

if(l==0)
{
cout<<n<<endl;
strcpy(n,"");
return;
}
else
{
if(!(s[i]==β€˜p’&&(s[i+1]==β€˜i’||s[i+1]==’\0’)))
{
n[k++]=s[i];
l–;
pi(s,l,i+1);
}
else{
strcat(n,p);
k+=4;
l-=2;
pi(s,l,i+2);
}

}
}
int main()
{
int t;
cin>>t;
while(t–)
{
k=0;
char s[10000];
cin>>s;
int l=strlen(s);
pi(s,l,0);
}
}
plz help

@kingshuk441 you are using global variables and you are not resetting their values at any point, so i’d suggest using local variables and passing them off as parameters in the function. Arrays are passed by reference so you dont need to worry about extra memory.

can u plz rectify it and send it i have tried many times plz

i have passed the test cases using inbuild string functions

but i wanted to correct my solution plz help

@kingshuk441 there’s nothing wrong with using inbuilt functions :slight_smile:
As I said above, you are using global variables, use local variables instead to resolve the issue.

can u make changes in my code plz

hi @kingshuk441 https://ide.codingblocks.com/s/213102 i have made changes to your code it is working now.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.