109 lines
4.5 KiB
C++
109 lines
4.5 KiB
C++
// based on example from http://en.cppreference.com/w/cpp/numeric/random/rand
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <ctime>
|
|
#include <random>
|
|
#include <list>
|
|
#include <algorithm>
|
|
#include <unordered_map>
|
|
#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<int> distribution(0, 23);
|
|
|
|
for(int i = 0; i <= 41; i++) {
|
|
int rnd = distribution(generator);
|
|
array[i] = rnd;
|
|
}
|
|
|
|
unittest_stringSimilarity();
|
|
}
|
|
|
|
|
|
//TODO: Punkte gleichmässig verteilen
|
|
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<char, int> string1map;
|
|
std::unordered_map<char, int> string2map;
|
|
std::unordered_map<char, int> 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;
|
|
|
|
int equalCharCount = 0;
|
|
int equalChars = 0;
|
|
for(std::pair<char, int> count : characterCount) {
|
|
//BUG: equalCharCount ist nicht immer korrekt
|
|
if(string1map[count.first] == string2map[count.first]) equalCharCount++;//gleiche Anzahl an gleichen Zeichen
|
|
if(string1map[count.first] != 0 && string2map[count.first] != 0) equalChars++;//Zeichen exsistiert in beiden
|
|
}
|
|
if(equalChars > 0) {
|
|
points += characterCount.size() / equalChars * 10;
|
|
}
|
|
if(equalCharCount > 0) {
|
|
points += characterCount.size() / equalCharCount;
|
|
std::cout << "equalCharCount = " << equalCharCount << std::endl;
|
|
}
|
|
|
|
|
|
|
|
//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;
|
|
} |