-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPIreplacementWithRecursion.cpp
More file actions
61 lines (56 loc) · 1.08 KB
/
PIreplacementWithRecursion.cpp
File metadata and controls
61 lines (56 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <sstream>
#include <iomanip>
using namespace std;
string pi = "3.14";
string solve(int idx, string str)
{
if (str[idx] == str.size() || str[idx + 1] == str.size())
return str;
if (str[idx] == 'p' && str[idx + 1] == 'i')
{
int j = idx + 2;
while (str[j] != '\0')
j++;
while (j >= idx + 2)
{
str[j + 2] = str[j];
j--;
}
int i = 0;
while (i < 4)
{
str[idx] = pi[i];
idx++, i++;
}
return solve(idx, str);
}
else{
return solve(idx + 1, str);
}
}
int32_t main()
{
string str = "xpighpilmpipi";
cout<<solve(0, str)<<endl;
}