71 lines
1.9 KiB
C++
71 lines
1.9 KiB
C++
// based on example from http://en.cppreference.com/w/cpp/numeric/random/rand
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <ctime>
|
|
#include <random>
|
|
#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++) {
|
|
array[i] = distribution(generator);
|
|
}
|
|
|
|
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<char, int> string1map;
|
|
std::unordered_map<char, int> string2map;
|
|
|
|
for(char c : string1) {
|
|
string1map[c]++;
|
|
}
|
|
for(char c : string2) {
|
|
string2map[c]++;
|
|
}
|
|
|
|
//gleiche Anzahl an verschiedenen Zeichen +10 Punkte
|
|
if(string1map.size() == string2map.size()) points += 10;
|
|
|
|
//auf gleiche Zeichenanzahl testen
|
|
int equalChars = 0;
|
|
int equalCharCount = 0;
|
|
for(std::pair<char, int> count : string1map) {
|
|
if(string2map.find(count.first) != string2map.end()) equalChars++;
|
|
if(string2map[count.first] == count.second) equalCharCount++;
|
|
}
|
|
|
|
//TODO: Pnukte 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 << "Hello World | Hallo Welt ---> " << stringSimilarity("Hello World", "Hallo Welt") << std::endl;
|
|
std::cout << "bla | ping ---> " << stringSimilarity("bla", "ping") << std::endl;
|
|
} |