Skip to content

Commit

Permalink
Broken shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ockenheimer committed Dec 6, 2017
1 parent e597861 commit 36f2fc6
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 95 deletions.
118 changes: 23 additions & 95 deletions src/ai801_aufgaben/AI801_Aufgaben.java
@@ -1,104 +1,32 @@
package ai801_aufgaben; package ai801_aufgaben;


public class AI801_Aufgaben { import com.sun.xml.internal.ws.handler.MessageHandlerContextImpl;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import java.util.logging.Logger;


public class AI801_Aufgaben {

public static void main(String[] args) { public static void main(String[] args) {
long timestart; long timestart;
long timemerk; long timemerk;
long timemark; long timemark;
Aufgabe2 a2 = new Aufgabe2();
System.out.println( a2.getSumme(900000000));
// timestart = System.nanoTime();
// System.out.println(a2.getSumme(10000));
// timemark = System.nanoTime();
// System.out.println("Die erste Aufgabe dauerte " + (timemark - timestart) + " ns");
// timestart = System.nanoTime();
// System.out.println(a2.getSumme(20000));
// timemark = System.nanoTime();
// System.out.println("Die zweite Aufgabe dauerte " + (timemark - timestart) + " ns");
// timestart = System.nanoTime();
// System.out.println(a2.getSumme(40000));
// timemark = System.nanoTime();
// System.out.println("Die dritte Aufgabe dauerte " + (timemark - timestart) + " ns");
// timestart = System.nanoTime();
// System.out.println(a2.getSumme(80000));
// timemark = System.nanoTime();
// System.out.println("Die vierte Aufgabe dauerte " + (timemark - timestart) + " ns");
// timestart = System.nanoTime();
// System.out.println(a2.getSumme(160000));
// timemark = System.nanoTime();
// System.out.println("Die fünfte Aufgabe dauerte " + (timemark - timestart) + " ns");
// Aufgabe3 a3 = new Aufgabe3();
// System.out.println(a3.getSumme(1500000000));
// timestart = System.nanoTime();
// System.out.println(a3.getSumme(4000000));
// timemark = System.nanoTime();
// System.out.println("Die erste Aufgabe dauerte " + (timemark - timestart) + " ns");
// timestart = System.nanoTime();
// System.out.println(a3.getSumme(8000000));
// timemark = System.nanoTime();
// System.out.println("Die zweite Aufgabe dauerte " + (timemark - timestart) + " ns");
// timestart = System.nanoTime();
// System.out.println(a3.getSumme(12000000));
// timemark = System.nanoTime();
// System.out.println("Die dritte Aufgabe dauerte " + (timemark - timestart) + " ns");
// timestart = System.nanoTime();
// System.out.println(a3.getSumme(16000000));
// timemark = System.nanoTime();
// System.out.println("Die vierte Aufgabe dauerte " + (timemark - timestart) + " ns");
// timestart = System.nanoTime();
// System.out.println(a3.getSumme(20000000));
// timemark = System.nanoTime();
// System.out.println("Die fünfte Aufgabe dauerte " + (timemark - timestart) + " ns");
Aufgabe4 a4 = new Aufgabe4();
System.out.println(a4.getSumme(100000));
timestart = System.nanoTime();
System.out.println(a4.getSumme(10000));
timemark = System.nanoTime();
System.out.println("Die erste Aufgabe dauerte " + (timemark - timestart) + " ns");
timestart = System.nanoTime();
System.out.println(a4.getSumme(20000));
timemark = System.nanoTime();
System.out.println("Die zweite Aufgabe dauerte " + (timemark - timestart) + " ns");
timestart = System.nanoTime();
System.out.println(a4.getSumme(30000));
timemark = System.nanoTime();
System.out.println("Die dritte Aufgabe dauerte " + (timemark - timestart) + " ns");
timestart = System.nanoTime();
System.out.println(a4.getSumme(40000));
timemark = System.nanoTime();
System.out.println("Die vierte Aufgabe dauerte " + (timemark - timestart) + " ns");
timestart = System.nanoTime();
System.out.println(a4.getSumme(50000));
timemark = System.nanoTime();
System.out.println("Die fünfte Aufgabe dauerte " + (timemark - timestart) + " ns");
// Blatt2Aufgabe2 b2a2 = new Blatt2Aufgabe2();
// timestart = System.nanoTime();
// timemerk = System.nanoTime();
//System.out.println(b2a2.ackermann(1,4));
// timemark = System.nanoTime();
// System.out.println("Die erste Aufgabe dauerte " + (timemark - timestart) + " ns");
// timestart = System.nanoTime();
// System.out.println(b2a2.getAckermann(1, 4));
// timemark = System.nanoTime();
// System.out.println("Die zweite Aufgabe dauerte " + (timemark - timestart) + " ns");
// timestart = System.nanoTime();
// System.out.println(b2a2.getAckermann(2, 4));
// timemark = System.nanoTime();
// System.out.println("Die dritte Aufgabe dauerte " + (timemark - timestart) + " ns");
// timestart = System.nanoTime();
// System.out.println(b2a2.getAckermann(5,5));
// timemark = System.nanoTime();
//
// System.out.println("Die vierte Aufgabe dauerte " + (timemark - timestart) + " ns");
//
// long timestop = System.nanoTime();
// System.out.println("Alle Aufgaben dauerten " + (timestop - timemerk) + " ns");
//Blatt3Aufgabe2 b3a2 = new Blatt3Aufgabe2();
// b3a2.rekursivfak(10);
//System.out.println(b3a2.iterativ(100));
// System.out.println(b3a2.zufallRekursiv(100));

}


// Blatt4Aufgabe1 b4a1 = new Blatt4Aufgabe1();
// try {
// b4a1.einlesen("C:\\Users\\Markus\\OneDrive\\OneDrive - et.hs-fulda.de\\AI801 - Datenstrukturen und Algorithmen\\AI801_Aufgaben\\geheim.txt");
// } catch (FileNotFoundException ex) {
// Logger.getLogger(AI801_Aufgaben.class.getName()).log(Level.SEVERE, null, ex);
// }
// b4a1.suchen("Lotte");
// b4a1.suchen("ich");
// b4a1.suchen("Computer");
Blatt4Aufgabe3 b4a3 = new Blatt4Aufgabe3();
//b4a3.alphabet();
b4a3.suche("schaefer");
// Blatt4Aufgabe5 b4a5 = new Blatt4Aufgabe5();
//// b4a5.hashtableErstellen();
// }

}
} }
71 changes: 71 additions & 0 deletions src/ai801_aufgaben/Blatt4Aufgabe1.java
@@ -0,0 +1,71 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ai801_aufgaben;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Markus
*/
public class Blatt4Aufgabe1 {

public Blatt4Aufgabe1() {

}
static String[] woerter;

public String[] einlesen(String datei) throws FileNotFoundException {

String inhalt = "";

String zeile;
try {
BufferedReader br = new BufferedReader(new FileReader(new File(datei)));
while ((zeile = br.readLine())!= null) {
inhalt += zeile + " ";

}

} catch (IOException ex) {
Logger.getLogger(Blatt4Aufgabe1.class.getName()).log(Level.SEVERE, null, ex);

}

woerter = inhalt.split("(\\s|\\p{Punct})+");
return woerter;
}

//Aufgabe 2 aber bezieht sich ja auf das einlesen aus Aufgabe 1
public void suchen(String suche) {
int fundort = -1;
int anzahl = 0;

for (int i = 0; i < woerter.length-1; i++) {
if (woerter[i].equalsIgnoreCase(suche)) {
if (fundort == -1) {
fundort = i + 1;
}

anzahl++;
}
}
if (fundort == -1) {
System.out.println("Das Suchwort '" + suche + "' findet sich nicht im Text.");
} else {
System.out.println("Das Suchwort '" + suche + "' findet sich " + anzahl + "-mal im Text. Erstmals taucht es als Wort Nr. " + fundort + " auf.");
}
}

}
66 changes: 66 additions & 0 deletions src/ai801_aufgaben/Blatt4Aufgabe3.java
@@ -0,0 +1,66 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ai801_aufgaben;

import java.awt.dnd.DragGestureRecognizer;

/**
*
* @author Markus
*/
public class Blatt4Aufgabe3 {

public Blatt4Aufgabe3() {
}

public char[] alphabet() {
char[] alphabetArray = new char[26];
char c = 65;
for (int i = 0; i < alphabetArray.length; i++, c++) {
alphabetArray[i] = c;
}

return alphabetArray;
}

public int sucheBinaer(char[] charArray, char beginn, char ende, char suche, int counter) {

char mitte;
if ((beginn + ende) % 2 != 0) {
mitte = (char) ((beginn + ende + 1) / 2);
} else {
mitte = (char) ((beginn + ende) / 2);
}

if (suche > charArray[mitte]) {
counter += 1;
return sucheBinaer(charArray, mitte, ende, suche, counter);

}
if (suche < charArray[mitte]) {
counter += 1;
return sucheBinaer(charArray, beginn, mitte, suche, counter);

}

return counter;
}



public void suche(String name) {
char[] nameArray = name.toUpperCase().toCharArray();
char[] alphabetArray2 = alphabet();
int counter = 0;
for (int i = 0; i < nameArray.length; i++) {
counter = sucheBinaer(alphabetArray2, alphabetArray2[0], alphabetArray2[alphabetArray2.length - 1], nameArray[i], counter);

System.out.println("Der Buchstabe " + nameArray[i] + " brauchte " + counter + " Durchläufe um gefunden zu werden.");

}

}
}
43 changes: 43 additions & 0 deletions src/ai801_aufgaben/Blatt4Aufgabe5.java
@@ -0,0 +1,43 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ai801_aufgaben;

import java.io.FileNotFoundException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Markus
*/
public class Blatt4Aufgabe5 {

public void hashtableErstellen() {
Hashtable<String, Integer> ht = new Hashtable<>();
Blatt4Aufgabe1 b4a1 = new Blatt4Aufgabe1();

try {

String[] buch = b4a1.einlesen("C:\\Users\\Markus\\OneDrive\\OneDrive - et.hs-fulda.de\\AI801 - Datenstrukturen und Algorithmen\\AI801_Aufgaben\\geheim.txt");
for (int i = 0; i < buch.length; i++) {

if (ht.containsKey(buch[i])) {
int merker = ht.get(buch[i]);
ht.put(buch[i], merker + 1);
} else {
ht.put(buch[i], 1);
}
}
System.out.println(ht.containsKey("Johann"));
System.out.println(buch[0].length());
} catch (FileNotFoundException ex) {
System.out.println("Datei nicht da.");
}

}
}

0 comments on commit 36f2fc6

Please sign in to comment.