Universität Ulm,
Fakultät für Mathematik und Wirtschaftswissenschaften,
SAI
Lösung zu Blatt 2 --- Allgemeine Informatik II (WS 1999)
1. Zählen
MODULE Count;
IMPORT Read, Streams, Write;
VAR
ch: CHAR;
anum, math, other: INTEGER;
BEGIN
anum := 0; math := 0; other := 0;
WHILE Streams.ReadByte(Streams.stdin, ch) DO
CASE ch OF
| "0".."9", "A".."Z", "a".."z": INC(anum);
| "+", "*", "-", "/", "(", ")": INC(math);
ELSE INC(other);
END;
END;
Write.Int(anum, 3); Write.Line(" anum");
Write.Int(math, 3); Write.Line(" math");
Write.Int(other, 3); Write.Line(" other");
END Count.
3. Faulus
MODULE Faulus;
IMPORT Read, Streams, Strings, Write;
VAR
recDepth: INTEGER;
PROCEDURE Sweep(level: INTEGER; text: ARRAY OF CHAR);
(* text must be swept in 2^level parts *)
VAR
newtext: ARRAY 512 OF CHAR;
BEGIN
IF level = 1 THEN (* absolute part *)
(* just two halves left *)
Write.String("Ich fege die erste Haelfte");
Write.String(text); Write.Ln;
Write.String("Ich verschnaufe ein wenig."); Write.Ln;
Write.String("Ich fege die zweite Haelfte");
Write.String(text); Write.Ln;
Write.String("Ich verschnaufe ein wenig."); Write.Ln;
ELSE (* level > 1: recursive Part *)
COPY(" der ersten Haelfte", newtext);
Strings.Concatenate(newtext, text);
Sweep(level-1, newtext);
COPY(" der zweiten Haelfte", newtext);
Strings.Concatenate(newtext, text);
Sweep(level-1, newtext);
END;
END Sweep;
BEGIN
Write.String("recDepth: "); Read.Int(recDepth);
Sweep(recDepth, " der Platte.");
END Faulus.
Ingo Melzer, 29. April 1999