Getting this error :
/bin/run.sh: line 4: 17 Segmentation fault (core dumped) ./exe
Whats wrong with my logic?
this is my submitted code, u can have a look
Hi Seemant, Here is my code :
#include #include using namespace std; string f(string s, int i) { if(s.size() <= 1) return s; string res = f(s,i+1); if(i < s.size()-1 && s[i] == ‘p’ && s[i+1] == ‘i’) res = res.substr(0,i) + “3.14” + res.substr(i+2); return res; } int main() { int t; cin >> t; while(t–) { string s; cin >> s; cout << f(s,0) << endl; } return 0; }
In your implementation you are not changing the string
In your implementation you are not changing the string
u can look at this code
in ur code the problem is
the base case is never hit, ur sending the same s again and again
either send the s from that i onwards