-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeow.cpp
82 lines (63 loc) · 1.47 KB
/
meow.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
#include<iostream>
using namespace std;
string substring(int, int, string);
int find(string, string);
string replace(string, string, int, int);
string invert(string);
int main()
{
string text;
int index;
cout << "\nEnter your text: ";
getline(cin, text);
string new_string = substring(3, 7, text);
index = find("is", "teri shadi cancel.");
string new_string1 = replace("male", "My name is Maleek, what's yours?", 11, 16);
string new_string2 = invert("Albania");
cout << index << endl << new_string << endl << new_string1 << endl << new_string2;
return 0;
}
string substring(int start, int end, string text)
{
string selected = "";
for(int i = start; i < end; i++)
{
selected += text[i];
}
return selected;
}
int find(string pattern, string text)
{
for(int i = 0; i < text.length(); i++)
{
for(int j = 0; j < pattern.length(); j++)
{
if(text[j+i] != pattern[j])
{
break;
}
if(j == (pattern.length() - 1))
{
return i;
}
}
}
return 0;
}
string replace(string pattern, string text, int start, int end)
{
for(int i = start; i <= end; i++)
{
text[i] = pattern[i - start];
}
return text;
}
string invert(string text)
{
string revert;
for(int i = 0; i < text.length(); i++)
{
revert[i] = text[(text.length() - 1) - i];
}
return revert;
}