diff --git a/src/07_STD/MP/grundgeruest.cpp b/src/07_STD/MP/grundgeruest.cpp index 212c36d..85ee0d3 100644 --- a/src/07_STD/MP/grundgeruest.cpp +++ b/src/07_STD/MP/grundgeruest.cpp @@ -6,25 +6,27 @@ #include #include #include +#include +#include #include "grundgeruest.hpp" struct BinaryOctet { - bool evenParity; - char bitsAsDigits[8]; + bool evenParity; + char bitsAsDigits[8]; - BinaryOctet(int i) { + BinaryOctet(int i) { - } + } }; int main() { - std::srand(static_cast(std::time(0))); + std::srand(static_cast(std::time(nullptr))); int array[41]; std::default_random_engine generator; std::uniform_int_distribution distribution(0, 23); - for(int i = 0; i <= 41; i++) { + for (int i = 0; i <= 41; i++) { int rnd = distribution(generator); array[i] = rnd; } @@ -35,24 +37,103 @@ int main() { //TODO: Punkte gleichmässig verteilen int stringSimilarity(std::string string1, std::string string2) { - std::string alphabet = "abcdefghijklmnopqrstuvwxyzäöü"; //wenn gleicher String, gleich 100 Punkte geben, spart den Rest - if(string1 == string2) return 100; + if (string1 == string2) return 100; int points = 0; //gleiche Länge +10 Punkte - if(string1.length() == string2.length()) points += 10; + if (string1.length() == string2.length()) points += 10; - //Anzahl der verschiedenen Zeichen zählen + std::map charCount; + std::map charCountString1; + std::map charCountString2; + for (char c : string1) { + charCount[c]++; + charCountString1[c]++; + } + for (char c : string2) { + charCount[c]++; + charCountString2[c]++; + } + std::cout << charCount.size() << " : " << charCountString1.size() << " : " << charCountString2.size() << std::endl; + int equalCharsPercentage = static_cast((double(charCountString1.size()) / double(charCount.size())) * 100); + + points += equalCharsPercentage / 10; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /*//Anzahl der verschiedenen Zeichen zählen std::unordered_map string1map; std::unordered_map string2map; std::unordered_map characterCount; + std::set characters; for(char c : string1) { + characters.insert(c); string1map[c]++; characterCount[c]++; } for(char c : string2) { + characters.insert(c); string2map[c]++; characterCount[c]++; } @@ -60,26 +141,30 @@ int stringSimilarity(std::string string1, std::string string2) { //gleiche Anzahl an verschiedenen Zeichen +10 Punkte if(string1map.size() == string2map.size()) points += 10; - int equalCharCount = 0; + int caseSensitiveCount = 0; for(std::pair c : characterCount) { //gleiche Anzahl an gleichen Zeichen in beiden überprüfen int charCount = c.second / 2; if(charCount == string1map[c.first] && charCount == string2map[c.first]) { - equalCharCount++; + caseSensitiveCount++; + } + if(islower(c.first)) { + c.first = static_cast(toupper(c.first)); } - - if(isupper(c.first)) c.first = tolower(c.first); } - - //gleiche Anzahl an gleichen Zeichen +10 Punkte - if(equalCharCount == characterCount.size()) points += 10; + if(caseSensitiveCount == characterCount.size()) points += 10; + int caseInsensitiveCount = 0; + for(std::pair c : characterCount) { + int charCount = c.second / 2; + if(charCount == string1map[c.first] && charCount == string2map[c.first]) { + caseInsensitiveCount++; + } + } - - //TODO: Punkte für gleiche Buchstaben und gleiche Buchstaben Anzahl vergeben - + if(caseInsensitiveCount == characterCount.size()) points += 10;*/ return points; @@ -91,21 +176,22 @@ void unittest_stringSimilarity() { std::cout << "Hello World | Hallo Welt ---> " << stringSimilarity("Hello World", "Hallo Welt") << std::endl; std::cout << "bla | ping ---> " << stringSimilarity("bla", "ping") << std::endl; std::cout << "Lorem ipsum..... | Lorem ipsum ---> " << stringSimilarity("Lorem ipsum dolor sit amet, " - "consetetur sadipscing elitr, " - "sed diam nonumy eirmod tempor" - "invidunt ut labore et dolore " - "magna aliquyam erat, sed diam voluptua. " - "At vero eos et accusam et justo duo dolores " - "et ea rebum. Stet clita kasd gubergren, " - "no sea takimata sanctus est Lorem " - "ipsum dolor sit amet. " - "Lorem ipsum dolor sit amet, " - "consetetur sadipscing elitr, " - "sed diam nonumy eirmod tempor " - "invidunt ut labore et dolore magna " - "aliquyam erat, sed diam voluptua. " - "At vero eos et accusam et justo duo dolores " - "et ea rebum. Stet clita kasd gubergren, " - "no sea takimata sanctus est Lorem ipsum " - "dolor sit amet.", "Lorem ipsum") << std::endl; + "consetetur sadipscing elitr, " + "sed diam nonumy eirmod tempor" + "invidunt ut labore et dolore " + "magna aliquyam erat, sed diam voluptua. " + "At vero eos et accusam et justo duo dolores " + "et ea rebum. Stet clita kasd gubergren, " + "no sea takimata sanctus est Lorem " + "ipsum dolor sit amet. " + "Lorem ipsum dolor sit amet, " + "consetetur sadipscing elitr, " + "sed diam nonumy eirmod tempor " + "invidunt ut labore et dolore magna " + "aliquyam erat, sed diam voluptua. " + "At vero eos et accusam et justo duo dolores " + "et ea rebum. Stet clita kasd gubergren, " + "no sea takimata sanctus est Lorem ipsum " + "dolor sit amet.", "Lorem ipsum") + << std::endl; } \ No newline at end of file