-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path24.cpp
113 lines (97 loc) · 2.66 KB
/
24.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/******************************************************************************
reverse a string using recursion
*******************************************************************************/
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
void reverse(string str,int n)
{
if(n == 0)
{
return;
}
// "abc"
// str.substr(1) karne ke baad humare pass aya
// "bc"
// aur fir reverse chala (rest of the string ke liye that is bc)
// firse substr aur fir aya
// "c"
// ""-null
// jaise ji null aya to base case hit hua aur return hua aur print hota gaya
string restOfString=str.substr(1);
//yeh 1 ke badd ki string de dega
reverse(restOfString,n-1);
cout << str[0];
}
int main()
{
string s;
getline(cin,s);
int len=s.length();
reverse(s,len);
return 0;
}
/******************************************************************************
replace all pi with 3.14 using recursion
*******************************************************************************/
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
void replace(string str,int n)
{
if(n==0){
return;
}
if(str[0]=='p' && str[1]=='i'){
cout<<"3.14";
// callinf for the rest of the string
replace(str.substr(2),n-2);
}
else{
cout<<str[0];
replace(str.substr(1),n-1);
}
}
int main()
{
string s;
getline(cin,s);
int len=s.length();
replace(s,len);
return 0;
}
// input - pisrishpipisrishpipi
// output - 3.14srish3.143.14srish3.143.14
// https://drive.google.com/file/d/1UN0moEVSoWC-kNYucMnHnVurd1GEF0m8/view
/******************************************************************************
move all elements at last of the string
*******************************************************************************/
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
string moveAllx(string s,int n){
if(n==0){
return "";
}
char ch=s[0];
string ros=moveAllx(s.substr(1),n-1);
if(ch=='x'){
return (ros+ch);
// matlab agar humara jo pehle alphabet aa raha hai string ka agar voh x hai to
// hum return kar rahe hai ros(rest of string)+x matlab ab x at the end of the string
// x add ho jayenge
}
else{
// aur agar nahi ata x to directly ros return kardenge with ch
return (ch+ros);
// matlab voh character vahi rahega last main nahi
}
}
int main()
{
string s;
getline(cin,s);
int n=s.length();
cout<<moveAllx(s,n);
return 0;
}