bwinf:bwinf40a5:start
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende Überarbeitung | |||
bwinf:bwinf40a5:start [2023/07/03 09:38] – 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." | ||
+ | } | ||
+ | |||
+ | |||
+ | } | ||
</ | </ | ||
bwinf/bwinf40a5/start.1688377118.txt.gz · Zuletzt geändert: 2023/07/03 09:38 von Martin Pabst