bwinf:bwinf40a5:start
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
bwinf:bwinf40a5:start [2023/06/30 07:23] – angelegt Martin Pabst | bwinf:bwinf40a5:start [2023/07/03 10:27] (aktuell) – Martin Pabst | ||
---|---|---|---|
Zeile 8: | Zeile 8: | ||
<script type=" | <script type=" | ||
+ | new Hauptprogramm(" | ||
+ | |||
+ | |||
+ | |||
+ | class Hauptprogramm { | ||
+ | |||
+ | Data data; | ||
+ | |||
+ | | ||
+ | |||
+ | |||
+ | | ||
+ | data = new Data(filename); | ||
+ | |||
+ | istMessbar = new boolean[1001]; | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | void start() { | ||
+ | legeHinzu(0, | ||
+ | ausgabe(); | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | void legeHinzu(int indexNächstesGewicht, | ||
+ | |||
+ | int anzahlAktuellesGewicht = data.anzahlListe[indexNächstesGewicht]; | ||
+ | |||
+ | for (int i = -anzahlAktuellesGewicht; | ||
+ | |||
+ | int neuesGesamtgewicht = bisherigesGesamtgewicht + i * data.gewichte[indexNächstesGewicht]; | ||
+ | |||
+ | | ||
+ | istMessbar[neuesGesamtgewicht / 10] = true; | ||
+ | } | ||
+ | |||
+ | // Abbruchbedingung für die Rekursion | ||
+ | | ||
+ | legeHinzu(indexNächstesGewicht + 1, neuesGesamtgewicht); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | void ausgabe() { | ||
+ | |||
+ | int count = 0; | ||
+ | |||
+ | for (int i = 0; i <= 1000; i++) { | ||
+ | |||
+ | | ||
+ | println(i * 10 + " g"); | ||
+ | count++; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | println(count + " Gewichte im Bereich 10 g bis 10000 g sind mit dem vorgegebenen Gewichtssatz erreichbar." | ||
+ | } | ||
+ | |||
+ | |||
+ | } | ||
</ | </ | ||
<script type=" | <script type=" | ||
+ | class Data { | ||
+ | |||
+ | int anzahl; | ||
+ | int[] gewichte; | ||
+ | int[] anzahlListe; | ||
+ | |||
+ | | ||
+ | String[] lines = Files.read(filename).split(" | ||
+ | anzahl = Integer.parseInt(lines[0]); | ||
+ | gewichte = new int[anzahl]; | ||
+ | anzahlListe = new int[anzahl]; | ||
+ | |||
+ | for (int i = 0; i < anzahl; i++) { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | } | ||
+ | } | ||
</ | </ | ||
bwinf/bwinf40a5/start.1688109817.txt.gz · Zuletzt geändert: 2023/06/30 07:23 von Martin Pabst