| 
          Der optimale Treffpunkt für Jugendliche | 
           | 
		    | 
           | 
            | 
           | 
            | 
           | 
            | 
           | 
            | 
		   | 
         
       
			
			
			
				 
					 | 
					
						 
						
						
							 
								 | 
								 | 
								 | 
							 
							 
								| 
								 | 
									
									
										 
											 | 
											 | 
											 | 
											 | 
											 | 
											 | 
										 
										   
											   
									        PROGRAM Haeuserreihe; USES   CRT; CONST   tabmax = 10;                                      {Maximale Tabellengroesse} TYPE   ttab = ARRAY [1..tabmax] OF INTEGER;                           {Tabellentyp} PROCEDURE Einlesen(VAR tabelle : ttab; VAR anz1 : INTEGER);   {Einlesprozedur}   VAR kind : INTEGER;                                     {Anzahl jugendliche}       ende : BOOLEAN;                                       {Abbruchbedingung}       i    : INTEGER;                                           {Laufvariable}   BEGIN     i    := 0;     ende := FALSE;     anz1 := 0;     WHILE (NOT(ende)) AND (i < tabmax)DO     {Bis ende = TRUE oder i zu gross}       BEGIN         i := i + 1;                                              {Hochzaehlen}         WRITE('Haus Nr.',i:2,':  ');         READLN(kind);                                           {Kinderanzahl}         IF kind <= 0 THEN                                    {Falsche Eingabe}           BEGIN             ende := TRUE;                                            {Abbruch}             anz1 := anz1 - 1;                         {Falschen Wert loeschen}           END         ELSE           tabelle[i] := kind;               {Zahl wird in Tabelle gespeichert}           anz1 := anz1 + 1;                      {Tabellenanzahl wird erhoeht}      END; END; FUNCTION Haussuche(tabelle : ttab; anz1 : INTEGER) : INTEGER;   VAR j, l  : INTEGER;                                          {Laufvariable}       pos   : INTEGER;                                              {Position}       kind1 : INTEGER;                                         {Linke Haelfte}       kind2 : INTEGER;                                        {Rechte Haelfte}       ende  : BOOLEAN;                                      {Abbruchbedingung}       pruef : INTEGER;            {Prueft ob er nicht im anderen IF-Zweig war} BEGIN     kind1 := 0;     kind2 := 0;     pruef := 0;     l     := 0;     ende  := FALSE;     pos := (anz1 + 1) DIV 2;                           {Mittelposition bilden}     WHILE NOT ende DO                                        {Bis Ende = TRUE}       BEGIN         l := 0;          FOR j := 1 TO pos DO                 {Die erste Haelfte wird summiert}           BEGIN              l := l + 1;             kind1 := tabelle[j] * l + kind1;                   {Weg berechnet}           END;         l := 0;         FOR j := pos TO anz1 DO             {Die zweite Haelfte wird summiert}           BEGIN             l := l + 1;             kind2 := tabelle[j] * l + kind2;                   {Weg berechnet}           END;         IF kind1 = kind2 THEN              {Wenn links und rechts gleich wird}           ende := TRUE         ELSE           IF kind1 > kind2 THEN              {Wenn erste Haelfte groesser ist}             BEGIN               pos   := pos - 1;                     {Position wird verringert}               IF pruef = 2 THEN                {Falls er im anderen Zweig war}                 ende := TRUE;               pruef := 1;                           {Pruef wird auf 1 gesetzt}             END           ELSE             BEGIN               pos := pos + 1;                          {Position wird erhoeht}               IF pruef = 1 THEN                {Falls er im anderen Zweig war}                 ende := TRUE               ELSE                 pruef := 2;                                  {Pruef wird zu 2}       END;   END;   Haussuche := pos;                    {Position wird der Funktion uebergeben} END;
  VAR   Haeuser : ttab;                                                       {Haus}   anz     : INTEGER;                                                  {Anzahl}
  BEGIN   CLRSCR;   WRITE('Wie viele Jugendliche befinden sich im jeweiligen Haus?');   WRITELN('( 0 = Abbruch )');   Einlesen(haeuser,anz);                                     {Einleseprozedur}   WRITE('Der optimale Treffpunkt ist Hausnummer ',Haussuche(Haeuser, anz));   READLN;                                     {Ausgabe der idealen Hausnummer} END.
										     | 
									       
									  
								   
									
							   | 
								 | 
							 
							 
								 | 
								 | 
								 | 
							 
						 
						
						
						
            
					 | 
					 | 
				 
			 
			
      
      
         
           | 
          
						Letzte Änderung: 09.02.2007 
            © Pädagogisches Institut für die deutsche Sprachgruppe 
            - Bozen. 2000 -				
		   | 
           | 
           | 
           | 
            | 
           | 
         
       
      
     | 
     | 
    
			
     |