-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisDuplicate.cpp
51 lines (39 loc) · 1.03 KB
/
isDuplicate.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
#include <string>
std::size_t duplicateCount(const std::string& in)
{
std::string lowercaseString;
std::size_t len = in.length();
std::size_t count = 0;
for(std::size_t i = 0; i < len; ++i)
{
char currChar = in[i];
if(currChar >= 'A' && currChar <= 'Z')
{
currChar = currChar - 'A' + 'a';
}
lowercaseString += currChar;
}
std::string check;
std::size_t lowercaseLen = lowercaseString.length();
for(std::size_t i = 0; i < lowercaseLen; ++i)
{
char currChar = lowercaseString[i];
bool isDup = false;
if(check.find(currChar) != std::string::npos)
continue;
for(std::size_t j = i + 1; j < lowercaseLen; ++j)
{
if(lowercaseString[j] == currChar)
{
isDup = true;
break;
}
}
if(isDup)
{
++count;
check += currChar;
}
}
return count;
}