Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program pratique;
- uses wincrt;
- var
- fs,fc:text;
- function majusc(ch:string):string;
- begin
- if ch = ''
- then majusc:=''
- else
- begin
- if ch[1] in ['a'..'z'] then
- begin
- majusc:= upcase(ch[1]) + majusc(ch);
- Delete(ch,1,1);
- end
- else
- begin
- majusc:= ch[1] + majusc(ch);
- Delete(ch,1,1);
- end;
- end;
- end;
- function verif(ch:string):Boolean;
- var i:integer;
- begin
- i:=1;
- while(i<=length(ch)) and (ch[i] in ['I','V','X','L','C','D','M']) do
- Inc(i);
- verif:= i > length(ch);
- end;
- function rom_ar(c:char):integer;
- var x:integer;
- begin
- case c of
- 'I': x:=1;
- 'V': x:=5;
- 'X': x:=10;
- 'L': x:=50;
- 'C': x:=100;
- 'D': x:=500;
- 'M': x:=1000;
- end;
- rom_ar:=x;
- end;
- function somme(ch:string):integer;
- var S,i:integer;
- begin
- S:=0;
- for i:=1 to Length(ch) do
- begin
- S:= S + rom_ar(ch[i]);
- if rom_ar(ch[i]) >= rom_ar(ch[i+1])
- then S:= S + rom_ar(ch[i+1])
- else S:= S - rom_ar(ch[i+1]);
- end;
- somme:=S;
- end;
- function ascii(ch:string):integer;
- var cha,a:string;
- n,e,i:integer;
- begin
- cha:='';
- a:='';
- for i:=1 to Length(ch) do
- begin
- str(ord(ch[i]),a);
- cha:= cha + a;
- end;
- Val(cha,n,e);
- ascii:=n;
- end;
- procedure Crypt(var fs,fc:text);
- var mot,x,R,d,b:string;
- begin
- reset(fs);
- rewrite(fc);
- while not(eof(fs)) do
- begin
- R:='';
- readln(fs,x);
- x:=x+' ';
- d:='';
- b:='';
- while(x<>'') do
- begin
- majusc(x);
- mot:=copy(x,1,pos(' ',x)-1);
- if verif(mot)
- then
- begin
- str(somme(mot),d);
- R:=R + d + ' ';
- end
- else
- begin
- str(ascii(mot),b);
- R:=R + b + ' ';
- end;
- Delete(x,pos(' ',x),1);
- end;
- writeln(fc,R);
- end;
- close(fs);
- close(fc);
- end;
- begin
- assign(fs,'C:\Pascal\devpratique\Source.txt');
- assign(fc,'C:\Pascal\devpratique\Crypt.txt');
- crypt(fs,fc);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement