-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplacePI.cpp
More file actions
49 lines (37 loc) · 829 Bytes
/
replacePI.cpp
File metadata and controls
49 lines (37 loc) · 829 Bytes
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
#include <iostream>
#include <strings.h>
using namespace std;
int length(char input[])
{
int len = 0;
for (int i = 0; input[i] != '\0'; i++)
{
len++;
}
return len;
}
void helper(char str[], int start){
if (str[start] == '\0' || str[start + 1] == '\0') {
return;
}
helper(str, start + 1);
if (str[start] == 'p' && str[start + 1] == 'i') {
for (int i = strlen(str); i >= start + 2; i--) {
str[i + 2] = str[i];
}
str[start] = '3';
str[start + 1] = '.';
str[start + 2] = '1';
str[start + 3] = '4';
}
}
void replacePi(char input[]) {
int n = length(input);
helper(input, 0);
}
int main() {
char input[10000];
cin.getline(input, 10000);
replacePi(input);
cout << input << endl;
}