Exercice 3 Devoir du synthese N1
Page 1 sur 1
Exercice 3 Devoir du synthese N1
program nom_prg;
uses wincrt;
type
mat=array[1..50,1..50] of char;
var
f,g:text;
m:mat;
ch,ch1:string;
procedure remplir_mat (var m:mat; var n :integer; ch:string);
var
i,j,k:integer; h:real;
begin
while not ( (length(ch) mod ( round(sqrt(length(ch)))) = 0)) do
begin
ch:=concat(' ',ch);
end;
h:=sqrt(length(ch));
n:=round(h);
k:=1;
for i:= 1 to n do
begin
for j:= 1 to n do
begin
m[j,i]:=ch[k];
k:=k+1;
end;
end;
for i:= 1 to n do
begin
for j:=1 to n do
write(m[i,j]);
end;
end;
function crypter (m:mat;n:integer):string;
var
i,j:integer;
ch:string;
begin
ch:='';
for i:= 1 to n do
begin
for j:= 1 to n do
begin
ch:=concat(ch,m[i,j]);
end;
end;
crypter:=ch;
end;
procedure cryptage (var f,g:text ) ;
var
m:mat;
n:integer;
ch:string;
begin
reset(f);
rewrite(g);
while not(eof(f)) do
begin
readln(f,ch);
remplir_mat(m,n,ch);
ch:=crypter(m,n);
writeln(g,ch);
end;
close(f);
close(g);
end;
begin
assign(f,'c:\source.txt');
assign(g,'c:\cryptage.txt');
cryptage(f,g);
reset(g);
reset(f);
while not (eof(g)) do
begin
readln(f,ch);
readln(g,ch1);
writeln(ch,' elle devient aprés avoir soumis à un cryptage : ',ch1);
end;
close(f);
close(g);
end.
uses wincrt;
type
mat=array[1..50,1..50] of char;
var
f,g:text;
m:mat;
ch,ch1:string;
procedure remplir_mat (var m:mat; var n :integer; ch:string);
var
i,j,k:integer; h:real;
begin
while not ( (length(ch) mod ( round(sqrt(length(ch)))) = 0)) do
begin
ch:=concat(' ',ch);
end;
h:=sqrt(length(ch));
n:=round(h);
k:=1;
for i:= 1 to n do
begin
for j:= 1 to n do
begin
m[j,i]:=ch[k];
k:=k+1;
end;
end;
for i:= 1 to n do
begin
for j:=1 to n do
write(m[i,j]);
end;
end;
function crypter (m:mat;n:integer):string;
var
i,j:integer;
ch:string;
begin
ch:='';
for i:= 1 to n do
begin
for j:= 1 to n do
begin
ch:=concat(ch,m[i,j]);
end;
end;
crypter:=ch;
end;
procedure cryptage (var f,g:text ) ;
var
m:mat;
n:integer;
ch:string;
begin
reset(f);
rewrite(g);
while not(eof(f)) do
begin
readln(f,ch);
remplir_mat(m,n,ch);
ch:=crypter(m,n);
writeln(g,ch);
end;
close(f);
close(g);
end;
begin
assign(f,'c:\source.txt');
assign(g,'c:\cryptage.txt');
cryptage(f,g);
reset(g);
reset(f);
while not (eof(g)) do
begin
readln(f,ch);
readln(g,ch1);
writeln(ch,' elle devient aprés avoir soumis à un cryptage : ',ch1);
end;
close(f);
close(g);
end.
Invité- Invité
Re: Exercice 3 Devoir du synthese N1
Bonjour Mondher
Je suis désolé pour le retard.
Est ce que ça marche ou non.
Je suis désolé pour le retard.
Est ce que ça marche ou non.
Re: Exercice 3 Devoir du synthese N1
Exercice 4 :
program ds1ex4_2012_2013;
uses wincrt;
type mat=array[1..20,1..20] of char;
var n:integer;
ch:string; s,c:text;
function crypter(ch:string):string;
var l,c,i:integer;
m:mat;
begin
n:=trunc(sqrt(length(ch)));
while n*n <>length(ch) do
begin
insert(' ',ch,1);
n:=trunc(sqrt(length(ch)));
end;
l:=1;c:=1;
for i:= 1 to length(ch) do
begin
m[l,c]:=ch[i];
c:=1+c;
if c>n then
begin
c:=1;l:=l+1;
end;
end;
i:=1;
for c:=1 to n do
for l:=1 to n do
begin
ch[i]:=m[l,c];
inc(i);
end;
crypter:=ch;
end;
procedure remplir(var s,c:text);
begin
reset(s);rewrite(c);
while not eof(s) do
begin
readln(s,ch);
ch:=crypter(ch);
writeln(c,ch);
end;
close(s);close(c);
end;
begin
assign(s,'z:\4algo\devoirs\source.txt');
assign(c,'z:\4algo\devoirs\cryptage.txt');
remplir(s,c);
end.
program ds1ex4_2012_2013;
uses wincrt;
type mat=array[1..20,1..20] of char;
var n:integer;
ch:string; s,c:text;
function crypter(ch:string):string;
var l,c,i:integer;
m:mat;
begin
n:=trunc(sqrt(length(ch)));
while n*n <>length(ch) do
begin
insert(' ',ch,1);
n:=trunc(sqrt(length(ch)));
end;
l:=1;c:=1;
for i:= 1 to length(ch) do
begin
m[l,c]:=ch[i];
c:=1+c;
if c>n then
begin
c:=1;l:=l+1;
end;
end;
i:=1;
for c:=1 to n do
for l:=1 to n do
begin
ch[i]:=m[l,c];
inc(i);
end;
crypter:=ch;
end;
procedure remplir(var s,c:text);
begin
reset(s);rewrite(c);
while not eof(s) do
begin
readln(s,ch);
ch:=crypter(ch);
writeln(c,ch);
end;
close(s);close(c);
end;
begin
assign(s,'z:\4algo\devoirs\source.txt');
assign(c,'z:\4algo\devoirs\cryptage.txt');
remplir(s,c);
end.
Re: Exercice 3 Devoir du synthese N1
Salem Monsieur,
non ca marche
alors fau pa utiliser "arrondi" ?
non ca marche
alors fau pa utiliser "arrondi" ?
Invité- Invité
Re: Exercice 3 Devoir du synthese N1
il faut utiliser trunc (tronc) parce que arrondi peut donner tronc+1
exemple :
arrondi(3.75) donne 4
et tronc(3.75) donne 3
tu peux pas utiliser int (ent) : partie entière parce que en Pascal elle donne réel et non pas entier.
exemple :
arrondi(3.75) donne 4
et tronc(3.75) donne 3
tu peux pas utiliser int (ent) : partie entière parce que en Pascal elle donne réel et non pas entier.
Sujets similaires
» Devoir de synthèse N° 2
» Devoir de synthèse N°2
» Devoir de synthèse N°2
» Devoir de synthèse N°3
» Devoir de synthèse N°2
» Devoir de synthèse N°2
» Devoir de synthèse N°2
» Devoir de synthèse N°3
» Devoir de synthèse N°2
Page 1 sur 1
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum
|
|