42 lines
933 B
C++
42 lines
933 B
C++
#include <algorithm>
|
|
#include <cstddef>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <map>
|
|
|
|
size_t duplicateCount(const std::string& in); // helper for tests
|
|
|
|
std::string toLower(const char* input){
|
|
std::string temp = input;
|
|
std::transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
|
|
return temp;
|
|
}
|
|
|
|
size_t duplicateCount(const char* in)
|
|
{
|
|
// Convert to lower chars
|
|
std::string input = toLower(in);
|
|
|
|
// Start counting for every char
|
|
std::map<char, int> my_map;
|
|
for(auto character: input){
|
|
auto it = my_map.find(character);
|
|
if(it != my_map.end()){
|
|
it->second += 1;
|
|
} else {
|
|
my_map[character] = 1;
|
|
}
|
|
}
|
|
|
|
// Count how often we have a value higher than 1
|
|
int count = 0;
|
|
for(auto it: my_map){
|
|
if(it.second > 1)
|
|
count++;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
int main(){
|
|
std::cout << duplicateCount("TESTtest");
|
|
} |