// based on example from http://en.cppreference.com/w/cpp/numeric/random/rand #include #include #include #include #include #include #include #include "grundgeruest.hpp" struct BinaryOctet { bool evenParity; char bitsAsDigits[8]; BinaryOctet(int i) { } }; int main() { int array[41]; std::default_random_engine generator; std::uniform_int_distribution distribution(0, 23); for(int i = 0; i <= 41; i++) { int rnd = distribution(generator); array[i] = rnd; } unittest_stringSimilarity(); } int stringSimilarity(std::string string1, std::string string2) { //wenn gleicher String, gleich 100 Punkte geben, spart den Rest if(string1 == string2) return 100; int points = 0; //gleiche Länge +10 Punkte if(string1.length() == string2.length()) points += 10; //Anzahl der verschiedenen Zeichen zählen std::unordered_map string1map; std::unordered_map string2map; std::unordered_map characterCount; for(char c : string1) { string1map[c]++; characterCount[c]++; } for(char c : string2) { string2map[c]++; characterCount[c]++; } //gleiche Anzahl an verschiedenen Zeichen +10 Punkte if(string1map.size() == string2map.size()) points += 10; //auf gleiche Zeichenanzahl testen //gleiche Anzahl an gleichen Zeichen int equalCharCount = 0; int equalChars = 0; for(std::pair count : characterCount) { if(string1map[count.first] == string2map[count.second]) equalCharCount++; if(string1map[count.first] != 0 && string2map[count.first] != 0) equalChars++; } if(equalChars > 0) { points += characterCount.size() / equalChars * 10; } if(equalCharCount > 0) { points += characterCount.size() / equalCharCount; } //TODO: Punkte für gleiche Buchstaben und gleiche Buchstaben Anzahl vergeben return points; } void unittest_stringSimilarity() { std::cout << "Hallo Welt | Hallo Welt ---> " << stringSimilarity("Hallo Welt", "Hallo Welt") << std::endl; std::cout << "Hallo Welt | Hallo Baum --->" << stringSimilarity("Halllo Welt", "Hallo Baum") << std::endl; 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; }