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

View File

@ -1,41 +1,49 @@
#include <stdio.h> /* file main_mp2_FLOW_a.cpp */ #include <stdio.h> /* file main_mp2_FLOW_a.cpp */
#include "../../helpers/AnsiConsole.h" #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 INITPRINT(label) {firstLine=__LINE__;console.printText(2*currentTick,0,label,Colors::BLACK);}
#define PRINT printLineNumber(__LINE__) #define PRINT printLineNumber(__LINE__)
void printLineNumber(int lineNumber); void printLineNumber(int lineNumber);
void help(int i); void help(int i);
void help2(); void help2();
void recurse2(int i, int rounds); void recurse2(int i, int rounds);
void recurse2(int i, int rounds) { void recurse2(int i, int rounds) {
if(i == 0 && rounds == 2) { if (i == 0 && rounds == 2) {
help2(); help2();
} } else if (i == 0 && rounds == 1) {
else if(i == 0 && rounds == 1) {
recurse2(3, 0); recurse2(3, 0);
}else {recurse2((i-1), 2);} } else { recurse2((i - 1), 2); }
} }
void help2() {PRINT;
void help2() {
PRINT;
recurse2(3, 1); recurse2(3, 1);
PRINT; PRINT;
} }
void recurse(int i) { void recurse(int i) {
if(i == 0) {help(2); return;} if (i == 0) {
PRINT;recurse(i-1); 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 { else {
PRINT; PRINT;
recurse(3); recurse(3);
@ -43,13 +51,12 @@ void help(int i) {if(i % 2 == 0)PRINT;
} }
void iterationA(int x) { void iterationA(int x) {
for(int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
PRINT; PRINT;
if(x % 2 != 0) if (x % 2 != 0)
PRINT; PRINT;
else else
PRINT; PRINT;
} }
@ -61,39 +68,38 @@ void startA() {
} }
int main(int argc, const char * argv[]) { int main(int argc, const char *argv[]) {
console.clearScreen(); console.clearScreen();
currentColor = Colors::GREEN;
/* currentColor = Colors::GREEN;
* 1x Rekursion
* 1x Selektion
* 1x Subroutine
*
* 3x Aufrufe aus:
* 1x Rekursion
* 1x Hilfsfunktion
* 1x main
*/
startA(); /*
//recurse2(3, 2); * 1x Rekursion
* 1x Selektion
std::string s; * 1x Subroutine
std::cin >> s; *
* 3x Aufrufe aus:
* 1x Rekursion
return 0; * 1x Hilfsfunktion
* 1x main
*/
startA();
//recurse2(3, 2);
std::string s;
std::cin >> s;
return 0;
} }
void printLineNumber(int lineNumber) {
void printLineNumber(int lineNumber){ std::string line = std::to_string(lineNumber);
std::string line = std::to_string(lineNumber); currentTick++;
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(); unittest_stringSimilarity();
} }
//TODO: Punkte gleichmässig verteilen
int stringSimilarity(std::string string1, std::string string2) { int stringSimilarity(std::string string1, std::string string2) {
//wenn gleicher String, gleich 100 Punkte geben, spart den Rest //wenn gleicher String, gleich 100 Punkte geben, spart den Rest
if(string1 == string2) return 100; if(string1 == string2) return 100;
@ -56,25 +58,27 @@ int stringSimilarity(std::string string1, std::string string2) {
//gleiche Anzahl an verschiedenen Zeichen +10 Punkte //gleiche Anzahl an verschiedenen Zeichen +10 Punkte
if(string1map.size() == string2map.size()) points += 10; if(string1map.size() == string2map.size()) points += 10;
//auf gleiche Zeichenanzahl testen
//gleiche Anzahl an gleichen Zeichen
int equalCharCount = 0; int equalCharCount = 0;
int equalChars = 0; int equalChars = 0;
for(std::pair<char, int> count : characterCount) { for(std::pair<char, int> count : characterCount) {
if(string1map[count.first] == string2map[count.second]) equalCharCount++; //BUG: equalCharCount ist nicht immer korrekt
if(string1map[count.first] != 0 && string2map[count.first] != 0) equalChars++; 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) { if(equalChars > 0) {
points += characterCount.size() / equalChars * 10; points += characterCount.size() / equalChars * 10;
} }
if(equalCharCount > 0) { if(equalCharCount > 0) {
points += characterCount.size() / equalCharCount; points += characterCount.size() / equalCharCount;
std::cout << "equalCharCount = " << equalCharCount << std::endl;
} }
//TODO: Punkte für gleiche Buchstaben und gleiche Buchstaben Anzahl vergeben //TODO: Punkte für gleiche Buchstaben und gleiche Buchstaben Anzahl vergeben
return points; return points;
} }