Skip to content
Snippets Groups Projects
Commit 2cf99bea authored by Michael Ghebremussie's avatar Michael Ghebremussie
Browse files

Add new file

parent 2a614096
No related branches found
No related tags found
No related merge requests found
main 0 → 100644
#include <iostream>
#include <list>
#include <fstream>
#include "Cards.cpp"
#include <string>
#include <cstring>
using namespace std;
const double tolerance = 0.2675;
//Aufgabe 1
// Implementiert den Algorithmus zur Berechnung der Levensthein-Distanz (LD) (5P).
int get_l_distance(string zeile, string spalte) {
// Initialise a 2d Matrix with the length of the word
int M[zeile.length() + 1][spalte.length() + 1];
for (int ZEILE = 0; ZEILE < zeile.length() + 1; ZEILE++) {
for (int SPALTE = 0; SPALTE < spalte.length() + 1; SPALTE++) {
M[ZEILE][SPALTE] = 0;
if (ZEILE == 0) {
M[ZEILE][SPALTE] = SPALTE;
}
if (SPALTE == 0) {
M[ZEILE][SPALTE] = ZEILE;
}
}
}
for (int ZEILE = 1; ZEILE < zeile.length() + 1; ZEILE++) {
for (int SPALTE = 1; SPALTE < spalte.length() + 1; SPALTE++) {
int c = 1;
if (zeile[ZEILE - 1] == spalte[SPALTE - 1]) {
c = 0;
}
int rep = M[ZEILE - 1][SPALTE - 1] + c;
int ins = M[ZEILE][SPALTE - 1] + 1;
int del = M[ZEILE - 1][SPALTE] + 1;
M[ZEILE][SPALTE] = min(rep, min(ins, del));
}
}
return M [zeile.length()][spalte.length()];
}
int main() {
ifstream scrambledFile("scrambled.txt");
list<Cards> cardList;
string singleLine;
//Aufgabe 3
while (getline(scrambledFile, singleLine)) {
//string singleLine copied in char Array
int n = singleLine.length();
char singleLineArray[n + 1];
strcpy(singleLineArray, singleLine.c_str());
//singleLineArray split in substrings
char *singleLineSubstring = strtok(singleLineArray, "|");
string cardInfoArr[5];
//Logic for seperating the Substrings
int j = 0;
while (singleLineSubstring) {
//Substring (Kartenattribute) werden in cardInfoArrgeschrieben
cardInfoArr[j] = singleLineSubstring;
j++;
singleLineSubstring = strtok(nullptr, "|");
}
//initalising new Card Object
Cards newCard;
//setting Card Attribute
newCard.setName(cardInfoArr[0]);
newCard.setMana(cardInfoArr[1]);
newCard.setCmc(cardInfoArr[2]);
newCard.setType(cardInfoArr[3]);
newCard.setCount(cardInfoArr[4]);
//add Card in card List
cardList.push_back(newCard);
}
scrambledFile.close();
//Aufgabe 4
ofstream cardWrite("cardOutput.txt");
for (Cards c: cardList) {
cardWrite << c.getName() << "|" << c.getMana() << "|" << c.getCmc() << "|" << c.getType() << "|" << c.getCount()
<< "\n";
}
cardWrite.close();
//Aufgabe 5
ifstream reference("reference.txt");
list<string> referenceNames;
while (getline(reference, singleLine)) {
referenceNames.push_back(singleLine);
}
reference.close();
//Aufgabe 6
list<Cards> repairedCards;
for (Cards card: cardList) {
for (string str: referenceNames) {
int l_dist = get_l_distance(card.getName(), str);
if (l_dist < card.getName().length() * tolerance) {
card.setName(str);
repairedCards.push_back(card);
break;
}
}
}
//Aufgabe 7
// create a new txt file called repairedCards
ofstream repairedCardsWrite("repairedCards.txt");
for (Cards crd: repairedCards) {
repairedCardsWrite << crd.getName() << "|" << crd.getMana() << "|" << crd.getCmc() << "|" << crd.getType()
<< "|" << crd.getCount() << "\n";
}
repairedCardsWrite.close();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment