Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Inf3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marcel Kehrberg
Inf3
Commits
2cf99bea
Commit
2cf99bea
authored
2 years ago
by
Michael Ghebremussie
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parent
2a614096
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main
+150
-0
150 additions, 0 deletions
main
with
150 additions
and
0 deletions
main
0 → 100644
+
150
−
0
View file @
2cf99bea
#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;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment