07_STD_MP: Fehler bei komplett unterschiedlichen Strings behoben, neuen beim Zählen gleicher Zeichen gefunden

This commit is contained in:
Johannes Theiner 2018-10-02 11:26:26 +02:00
parent cb3cb443cd
commit f7257a2cc8
3 changed files with 62 additions and 53 deletions

View File

@ -1,6 +1,8 @@
#include <stdio.h> /* file main_mp2_FLOW_a.cpp */
#include "../../helpers/AnsiConsole.h"
//TODO: verstehen
AnsiConsole console; int firstLine; int currentTick; Colors currentColor;
#define INITPRINT(label) {firstLine=__LINE__;console.printText(2*currentTick,0,label,Colors::BLACK);}
#define PRINT printLineNumber(__LINE__)
@ -44,9 +46,6 @@ void test() {
void start_Sequence(void){
INITPRINT("Sequence");
PRINT;

View File

@ -1,41 +1,49 @@
#include <stdio.h> /* file main_mp2_FLOW_a.cpp */
#include "../../helpers/AnsiConsole.h"
AnsiConsole console; int firstLine; int currentTick; Colors currentColor;
AnsiConsole console;
int firstLine;
int currentTick;
Colors currentColor;
#define INITPRINT(label) {firstLine=__LINE__;console.printText(2*currentTick,0,label,Colors::BLACK);}
#define PRINT printLineNumber(__LINE__)
void printLineNumber(int lineNumber);
void help(int i);
void help2();
void recurse2(int i, int rounds);
void recurse2(int i, int rounds) {
if(i == 0 && rounds == 2) {
if (i == 0 && rounds == 2) {
help2();
}
else if(i == 0 && rounds == 1) {
} else if (i == 0 && rounds == 1) {
recurse2(3, 0);
}else {recurse2((i-1), 2);}
} else { recurse2((i - 1), 2); }
}
void help2() {PRINT;
void help2() {
PRINT;
recurse2(3, 1);
PRINT;
}
void recurse(int i) {
if(i == 0) {help(2); return;}
PRINT;recurse(i-1);
if (i == 0) {
help(2);
return;
}
PRINT;
recurse(i - 1);
}
void help(int i) {if(i % 2 == 0)PRINT;
void help(int i) {
if (i % 2 == 0)PRINT;
else {
PRINT;
recurse(3);
@ -43,11 +51,10 @@ void help(int i) {if(i % 2 == 0)PRINT;
}
void iterationA(int x) {
for(int i = 0; i < 3; ++i)
for (int i = 0; i < 3; ++i)
PRINT;
if(x % 2 != 0)
if (x % 2 != 0)
PRINT;
else
PRINT;
@ -61,7 +68,7 @@ void startA() {
}
int main(int argc, const char * argv[]) {
int main(int argc, const char *argv[]) {
console.clearScreen();
@ -89,11 +96,10 @@ int main(int argc, const char * argv[]) {
}
void printLineNumber(int lineNumber){
void printLineNumber(int lineNumber) {
std::string line = std::to_string(lineNumber);
currentTick++;
console.printText(currentTick*2-1, 1+lineNumber-firstLine, line, currentColor);
console.printText(currentTick * 2 - 1, 1 + lineNumber - firstLine, line, currentColor);
}

View File

@ -31,6 +31,8 @@ int main() {
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;
@ -56,25 +58,27 @@ int stringSimilarity(std::string string1, std::string string2) {
//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<char, int> count : characterCount) {
if(string1map[count.first] == string2map[count.second]) equalCharCount++;
if(string1map[count.first] != 0 && string2map[count.first] != 0) equalChars++;
//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;
}