more katas

This commit is contained in:
2019-12-09 11:49:52 +01:00
parent aa223cf1c5
commit 97c0e43874
4 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
#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");
}