-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathString_Class.hpp
More file actions
145 lines (121 loc) · 2.51 KB
/
String_Class.hpp
File metadata and controls
145 lines (121 loc) · 2.51 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#pragma once
#include <iostream>
#include <string>
#include <cstring>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;
class String_Class {
string str;
char* str2;
int count;
public:
String_Class(){}
String_Class(string input) : str(input) {}
~String_Class() { }
string toString() {
return str;
}
bool CheckUniqueCharReturnBool() {
map<char, int> m;
if (str.length() == 0)
return false;
for (unsigned i = 0; i < str.length(); i++)
{
if (m.find(str.at(i) ) == m.cend())
m.insert_or_assign(str.at(i), 1);
else
return false;
}
return true;
}
string DeleteUniqueCharReturnBool() {
map<char, int> m;
int last = 0;
string result = "";
if (str.length() == 0)
return false;
for (unsigned i = 0; i < str.length(); i++)
{
if (m.find(str.at(i)) == m.cend())
{
m.insert_or_assign(str.at(i), 1);
result += str.at(i);
}
else
{
continue;
}
}
return result;
}
int replaceSpaceswithPercent20ReturnCount() {
int count = 0;
string result = "";
for (unsigned i = 0; i < str.length(); i++)
{
if (str.at(i) != ' ')
result += str.at(i);
else
{
result += '%20';
count++;
}
}
str = result;
return count;
}
bool CheckAnagramReturnBool(string other)
{
map<char, int>m_self;
map<char, int>m_other;
//check for equal size and null size
if (str.length() != other.length() || (str.length() == 0 || other.length() == 0) )
return false;
//find mode for each character in self and other string
for (unsigned i = 0; i < str.length(); ++i) {
if ( m_self.find( str.at(i) ) != m_self.end() ) {
m_self.at(str.at(i))++;
}
else
{
m_self.insert_or_assign(str.at(i), 1);
}
if (m_other.find(other.at(i)) != m_other.end() ) {
m_other.at(other.at(i))++;
}
else
{
m_other.insert_or_assign(other.at(i), 1);
}
}
map<char, int> ::iterator itM;
map<char, int> ::iterator itM2;
itM2 = m_self.begin();
for (itM = m_other.begin(); itM != m_other.end(); ++itM, ++itM2)
{
if (itM->second != itM2->second)
return false;
}
return true;
}
string ReverseCStringReturnResult(char* str2) {
string result = "";
int count = 0;
while (*str2 != '\0')
{
count++;
str2++;
}
count--;
str2--;
while (count >= 0)
{
result += *str2;
str2--;
count--;
}
return result;
}
};