Advertisement
Arfizato

bac2014 ya skon

Jun 24th, 2020
2,321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.73 KB | None | 0 0
  1. //https://www.kiteb.net/education/informatique/bac/bacinfo2014/bac-pratique-22052014-algo-14h.pdf
  2. program AyaSahbiSkon;
  3. uses WinCrt;
  4. Type
  5.     mat = Array [1..5,0..5] of char;
  6. var
  7.  m : mat ;
  8.  l : byte ;
  9.  cle,msg: string;
  10.  Procedure clean( var cle : string);
  11.     var
  12.         a : byte;
  13.     begin
  14.         for a:=Length(cle) DownTo 1 do
  15.             if pos(cle[a],cle) <> a then
  16.                 delete(cle,a,1);
  17.     end;   
  18.  Procedure remp(var m : mat ; cle: string);
  19.    var
  20.         a,b : byte;
  21.      begin
  22.         clean(cle);
  23.         for a:=1 to Length(cle) do
  24.             if (a mod 5 <> 0)  then  
  25.                  m[a div 5+1, a mod 5]:=cle[a]
  26.             else  
  27.                  m[a div 5, 5]:=cle[a];        
  28.                                                                                    
  29.             b:= ord('A');
  30.             while (a<=25) do
  31.                 begin
  32.                     if (pos(chr(b),cle) <>0 ) or (chr(b) = 'W') then
  33.                         b:=b+1
  34.                     else
  35.                         Begin
  36.                             if (a mod 5 <> 0)  then
  37.                                  m[a div 5+1, a mod 5]:=chr(b)
  38.                             else
  39.                                  m[a div 5, 5]:=chr(b);
  40.                             a:=a+1;
  41.                             b:=b+1;
  42.                         end;     
  43.                 end;                        
  44.      end;
  45.         Function position(c:char ; m : mat): string;
  46.              var
  47.                 a,b: byte ;
  48.                 ch: string;
  49.              begin
  50.                 a:=1;
  51.                 b:=1;
  52.                 if c = ' '  then
  53.                     ch:= c
  54.                 else if c= 'W' then
  55.                     ch:=position('V',m)
  56.                 else
  57.                     begin
  58.                         while m[a,b] <> Upcase(c) do
  59.                             begin
  60.                                 b:=b+1;
  61.                                 if b= 6 then
  62.                                     begin
  63.                                         b:=1;
  64.                                         a:=a+1;
  65.                                     end;
  66.                             end;
  67.                         ch:=chr(ord('0')+a)+  chr(ord('0')+b)  ;
  68.                     end;
  69.                 position:=ch;                  
  70.              end;
  71.      function crypt(msg: String; m :mat): string;
  72.         var
  73.         a : byte;
  74.         ch : String;
  75.         begin
  76.             ch:='';
  77.          for a:=1 to Length(msg) do
  78.                 ch:=ch+position(msg[a],m);
  79.          crypt := ch;
  80.         end;
  81. begin
  82.     readln(msg);
  83.     readln(cle);
  84.     remp(m,cle);
  85.     writeln(crypt(msg,m));
  86. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement