File tree 1 file changed +63
-0
lines changed
1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* Hacker Blocks */
2
+ /* Title - Replace PI */
3
+ /* Created By - Akash Modak */
4
+ /* Date - 06/07/2020 */
5
+
6
+ // Replace all occurrences of pi with 3.14
7
+
8
+ // Input Format
9
+ // Integer N, no of lines with one string per line
10
+
11
+ // Constraints
12
+ // 0 < N < 1000
13
+ // 0 <= len(str) < 1000
14
+
15
+ // Output Format
16
+ // Output result one per line
17
+
18
+ // Sample Input
19
+ // 3
20
+ // xpix
21
+ // xabpixx3.15x
22
+ // xpipippixx
23
+ // Sample Output
24
+ // x3.14x
25
+ // xab3.14xx3.15x
26
+ // x3.143.14p3.14xx
27
+ // Explanation
28
+ // All occurrences of pi have been replaced with "3.14".
29
+
30
+ #include < iostream>
31
+ using namespace std ;
32
+ void replacepi (char *a,int i){
33
+ if (a[i]==' \0 ' or a[i+1 ]==' \0 ' )
34
+ return ;
35
+ if (a[i]==' p' and a[i+1 ]==' i' ){
36
+ int j=i;
37
+ while (a[j]!=' \0 ' )
38
+ j++;
39
+ while (j>=i+2 ){
40
+ a[j+2 ]=a[j];
41
+ j--;
42
+ }
43
+ a[i]=' 3' ;
44
+ a[i+1 ]=' .' ;
45
+ a[i+2 ]=' 1' ;
46
+ a[i+3 ]=' 4' ;
47
+ replacepi (a,i+4 );
48
+ }
49
+ else
50
+ replacepi (a,i+1 );
51
+ }
52
+ int main () {
53
+ int t;
54
+ cin>>t;
55
+ while (t--){
56
+ char a[1000 ];
57
+ cin>>a;
58
+ // int n = strlen(a);
59
+ replacepi (a,0 );
60
+ cout<<a<<endl;
61
+ }
62
+ return 0 ;
63
+ }
You can’t perform that action at this time.
0 commit comments