Advertisement
ridjis

zadatak 3.10a

Jun 4th, 2014
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MODULE zad310a;
  2.  
  3. FROM InOut IMPORT WriteLn,WriteString,ReadString,WriteInt;
  4. FROM FIO IMPORT File,Close,Open,Create,RdInt,WrInt,EOF,WrLn;
  5. FROM Stek IMPORT StekTip,Top,Pop,Push,Empty,MakeNull;
  6.  
  7. CONST i1 = "s1i.txt";
  8.       i2 = "s2i.txt";
  9.  
  10. VAR str : ARRAY [1..256] OF CHAR;
  11.     s1,s2:StekTip;
  12.     ok:BOOLEAN;
  13.  
  14. PROCEDURE Ucitaj(imeF:ARRAY OF CHAR; VAR stek:StekTip; VAR ok:BOOLEAN);
  15. VAR f:File;
  16.     n:INTEGER;
  17. BEGIN
  18.   MakeNull(stek);
  19.   f:=Open(imeF);
  20.   EOF:=FALSE;
  21.   WHILE NOT EOF DO
  22.     n:=RdInt(f);
  23.     Push(stek,n,ok);
  24.   END;
  25.   Close(f);
  26. END Ucitaj;
  27.  
  28. PROCEDURE Ispis(stek:StekTip;VAR ok:BOOLEAN);
  29. VAR n:INTEGER;
  30. BEGIN
  31.   WHILE NOT Empty(stek) DO
  32.     Top(stek,n,ok);
  33.     Pop(stek,ok);
  34.     WriteInt(n,1);
  35.     WriteLn;
  36.   END;
  37. END Ispis;
  38.  
  39. PROCEDURE UkloniParne(VAR stek:StekTip;VAR ok:BOOLEAN);
  40. VAR n:INTEGER;
  41.     m:BOOLEAN;
  42. BEGIN
  43.   m:=TRUE;
  44.   WHILE m AND NOT Empty(stek) DO
  45.     Top(stek,n,ok);
  46.     IF (n MOD 2 = 0) THEN
  47.       Pop(stek,ok);
  48.     ELSE
  49.       m:=FALSE;
  50.     END;
  51.   END;
  52. END UkloniParne;
  53.  
  54. PROCEDURE UkloniSled(VAR stek:StekTip; VAR ok:BOOLEAN);
  55. VAR x,y:INTEGER;
  56.     m:BOOLEAN;
  57. BEGIN
  58.   m:=TRUE;
  59.   WHILE m AND NOT Empty(stek) DO
  60.     Top(stek,x,ok);
  61.     Pop(stek,ok);
  62.     Top(stek,y,ok);
  63.     IF (x<y) OR Empty(stek) THEN
  64.       Push(stek,x,ok);
  65.       m:=FALSE;
  66.     END;
  67.   END;
  68. END UkloniSled;
  69.  
  70. PROCEDURE Sacuvaj(imeF:ARRAY OF CHAR; VAR stek:StekTip;VAR ok:BOOLEAN);
  71. VAR f:File;
  72.     n:INTEGER;
  73. BEGIN
  74.   f:=Create(imeF);
  75.   WHILE NOT Empty(stek) DO
  76.     Top(stek,n,ok);
  77.     Pop(stek,ok);
  78.     WrInt(f,n,0);
  79.     WrLn(f);
  80.   END;
  81.   Close(f);
  82. END Sacuvaj;
  83.  
  84. BEGIN
  85.   Ucitaj(i1,s1,ok);
  86.   Ucitaj(i2,s2,ok);
  87.  
  88.   UkloniParne(s1,ok);
  89.   UkloniSled(s2,ok);
  90.  
  91.   Ispis(s1,ok);
  92.   WriteLn;
  93.   WriteLn;
  94.   Ispis(s2,ok);
  95.   WriteLn;
  96.  
  97.   WriteString('Unesite ime fajla: '); //int1.txt
  98.   ReadString(str);
  99.   Sacuvaj(str,s1,ok);
  100.   WriteLn;
  101.   WriteString('Unesite ime 2. fajla: '); //int2.txt
  102.   ReadString(str);
  103.   Sacuvaj(str,s2,ok);
  104.   WriteLn;
  105.  
  106. END zad310a.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement