Correction Des Epreuves D Informatique sujet1: Program bac_2017_25_mai_s1; Uses Wincrt; Type tab = Array [1..20] Of Integer; n: Integer; T: tab; _--Pratique--_ 2017 Procedure saisir( n:integer); write('donner la taille du tableau :'); Readln(n); Until n In [3..20]; Procedure remplir( T:tab;n:Integer); For i:=1 To n Do Readln(T[i]); Until T[i]>0; Procedure afficher(t:tab;n:integer); i,s,j: Integer; ch,d,chd: string; ch := ''; j := 0; If (T[i] Mod 2=0) and (i<=n) Then Str(T[i],d); ch := ch+d+',' ; End chd := ch; s := 0; If Pos(',',chd)<>0 Then s := s+1; Delete(chd,Pos(',',chd),1); Until Pos(',',chd)=0; If (ch<>'') And (s>=2) Then j := j+1; ch := ''; Until i>n; Writeln('le nombre de séquences paires est ',j); Writeln('les séquences d''entiers pairs sont :'); ch := ''; If (T[i] Mod 2=0) and (i<=n) Then Str(T[i],d); ch := ch+d+',' ; End chd := ch; s := 0; If Pos(',',chd)<>0 Then s := s+1; Delete(chd,Pos(',',chd),1); Until Pos(',',chd)=0; If (ch<>'') And (s>=2) Then Writeln(Copy(ch,1,Length(ch)- 1)); ch := ''; Until i>n; saisir(n); remplir(t,n); afficher(t,n); End. MEDDEB Mohamed Page 1
sujet2: Program bac_2017_25_mai_s2; Uses Wincrt; n: string; Function verif(n:string): Boolean; test: Boolean; If n[i] In ['0'..'9'] Then test := True test := False; Until (Not(test)) Or (i>=length(n)); verif := (test And (Length(n)=8)); Procedure saisir( n:string); write('saisir le numero de telephone à deviner : '); Readln(n); Until verif(n); Function norepeat(ch:string): string; ch2: string; ch2 := ''; For i:=1 To Length(ch) Do If Pos(ch[i],ch2)=0 Then ch2 := ch2+ch[i]; norepeat := ch2; Procedure deviner(n:string); i,j,k: Integer; ch: string; i := 8; Writeln('vous avez ',i,' essais'); write('proposer un numéro de téléphone :'); Readln(ch); Until verif(ch); If ch<>n Then j:=0; j:=j+1; k:=0; if ch[j]<>n[j] Then k:=k+1; if (n[k]=ch[j]) And (j<>k) then Writeln(ch[j],' qui est à la position ',j,' dans la proposition n''est pas à sa bonne position'); until (k>=length(n)) or ((n[k]=ch[j]) And (j<>k)); Until j>=length(ch); i := i-1; If i<>1 Then Writeln('il vous reste ',i,' essais') Writeln('il vous reste ',i,' essai'); For j:=1 To Length(ch) Do If ch[j]=n[j] Then write(ch[j]); End write('-'); Writeln; Until (n=ch) Or (i<=1); If n<>ch Then Writeln('désolé, vous avez perdu') Writeln('bravo, vous avez gagné'); saisir(n); Clrscr; deviner(n); End. MEDDEB Mohamed Page 2
sujet3: Program bac_2017_25_mai_s3; Uses Wincrt; ch: string; p: Integer; Function verif(ch:string): Boolean; test: Boolean; If Upcase(ch[i]) In ['A'..'Z',' '] Then test := True test := False; Until (Not(test)) Or (i>=length(ch)); verif := test; Procedure saisir( ch:string); Readln(ch); Until verif(ch); Function nbmot(ch:string): Integer; i,j,n: Integer; T: Array [1..200] Of string; j := 1; If Upcase(ch[i]) In ['A'..'Z'] Then T[j] := T[j]+ch[i] j := j+1; Until i>=length(ch); n := 0; For i:=1 To j Do If T[i]<>'' Then n := n+1; nbmot := n; Function crypter(ch:string;p:integer): String; i,ordch: Integer; Chrd: string; chrd:=''; For i:=1 To Length(ch) Do If ch[i]=' ' Then Chrd :=Chrd + ch[i] If ch[i] In ['A'..'Z'] Then ordch := Ord(ch[i])+p; While not(ordch In [65..91]) Do ordch := ordch-26; Chrd :=chrd + Chr(ordch); End If ch[i] In ['a'..'z'] Then ordch := Ord(ch[i])+p; While not(ordch In [97..123]) Do ordch := ordch-26; Chrd :=chrd + Chr(ordch); crypter:=chrd; saisir(ch); p := nbmot(ch); writeln(p); Writeln(crypter(ch,p)); End. MEDDEB Mohamed Page 3
sujet4: Program bac_2017_25_mai_s4; uses wincrt; cle,init,rib:string; End. saisir(init,rib); cle:=cle_iban(init); writeln('l''iban correspondant est : ',init+cle+rib); Function verif(ch:string):boolean; if ch[i] in ['A'..'Z'] then test:=true test:=false; until (i>=length(ch)) or (not(test)); verif:=test; sujet5: Program bac_2017_25_mai_s5; uses wincrt; type tab=array [1..250] of string; tableau=array [1..250] of longint; n:integer; tb,te:tab; tbu:tableau; procedure saisir(var init,rib:string); readln(init); Until (Length(init)=2) and (verif(init)); readln(rib); until length(rib) in [10..30]; function cle_iban(init:string):string; ch,ch1:string; d,i,e:integer; ch:=''; for i:=1 to length(init) Do str(ord(init[i])-55,ch1); ch:=ch+ch1; ch:=ch+'00'; val(ch,d,e); d:=98-(d mod 97); if d<10 then d:=d*10; str(d,ch); cle_iban:=ch; Function verifb(ch:string):boolean; s, if ch[i] in ['0'..'9','#'] then test:=true else test:=false; if ch[i]='#' then s:=s+1; until (i>=length(ch)) or (not(test)); verifb:=(test) and (s=1); function veriflength(ch:string):boolean; test1,test2:boolean; p:integer; p:=pos('#',ch); if length(copy(ch,1,p-1))<=3 then test1:=true else test1:=false; if length(copy(ch,p+1,length(ch)-p))<=3 then test2:=true else test2:=false; veriflength:=(test1) and (test2); function verif(ch:string):boolean; MEDDEB Mohamed Page 4
i:integer; if ch[i] in ['0'..'9'] then test:=true else test:=false; until (not(test)) or (i>=length(ch)); verif:=test; procedure remplir(var te,tb:tab;n:integer); readln(te[i]); until (verif(te[i])) and (length(te[i])=6); readln(tb[i]); until (verifb(tb[i])) and (veriflength(tb[i])); max:=tbu[1]; for i:=2 to n Do if tbu[i]>max then max:=tbu[i]; ch:=''; if max=tbu[i] then ch:=ch+te[i]+'-'; delete(ch,length(ch),1); writeln('le besoin budgétaire le plus élevé est ',max,' D et les écoles concernées sont : ',ch); end. write('donner le nombre d''écoles à visiter :'); readln(n); until n in [2..250]; remplir(te,tb,n); generer(tb,tbu,n); afficher(te,tbu,n); procedure generer(tb:tab;var tbu:tableau;n:integer); Const p1=80; p2=160; i,p,ntableaux,ntables,e:integer; p:=pos('#',tb[i]); val(copy(tb[i],1,p-1),ntableaux,e); val(copy(tb[i],p+1,length(tb[i])-p),ntables,e); tbu[i]:=(p1*ntableaux)+(p2*ntables); procedure afficher(te:tab;tbu:tableau;n:integer); ch:string; max:longint; MEDDEB Mohamed Page 5
sujet6: Program bac_2017_25_mai_s6; uses wincrt; code:string; sujet7: Program bac_2017_25_mai_s7; Uses Wincrt; mot,masque: string; function verif(ch:string):boolean; test,test1:boolean; begin if (ch[1] in ['A'..'Z']) then test1:=true else test1:=false; i:=1; if (i>1) and (ch[i] in ['0'..'9']) then test:=true else test:=false; until (i>=length(ch)) or not(test); verif:=test and test1 and (length(ch)=12); function authentique(ch:string):boolean; d,e,i,s:integer; aux:string; str(ord(ch[1])-64,aux); delete(ch,1,1); ch:=aux+ch; for i:=1 to length(ch) Do val(ch[i],d,e); s:=s+d; authentique:=(s mod 9 = 8); repeat write('saisir le code à valider :'); readln(code); until verif(code); if authentique(code) Then writeln('c''est un billet authentique') writeln('attention! ce billet n''est pas authentique'); end. Function verif(ch:string): Boolean; test: Boolean; If (Upcase(ch[i]) In ['A'..'Z']) Then test := True test := False; Until (i>=length(ch)) Or Not(test); verif := test And (Length(ch) In [5..20]); Function masquer(ch:string): string; ch1: string; ch1 := ''; ch1 := ch1+ch[1]; For i:=1 To (Length(ch)-2) Do ch1:=ch1+'-'; ch1 := ch1+ch[length(ch)]; masquer := ch1; Procedure remplace( ch:string;ch1:string;c:char); For i:=2 To (Length(ch)-1) Do If ch1[i]=c Then ch[i] := c; Procedure deviner(mot:string; masque:string); tentative: Integer; c: Char; Writeln('le mot à deviner est ',masque); MEDDEB Mohamed Page 6
tentative := Length(mot); Writeln('il vous reste ',tentative,' essai(s)'); write('proposer un caractere :'); Readln(c); Until (Upcase(c) In ['A'..'Z']); remplace(masque,mot,c); If (masque<>mot) Then tentative := tentative-1; if tentative<>0 Then Writeln('le mot à deviner est ',masque); Until (masque=mot) Or (tentative<=0); If (tentative<=0) Then Writeln('desole, vous avez perdu ') Writeln('bravo, vous avez gagne '); writeln('le mot masqué est : ',mot); write('saisir le mot à deviner :'); Readln(mot); Until verif(mot); Clrscr; masque := masquer(mot); deviner(mot,masque); End. sujet8: Program bac_2017_25_mai_s8; Uses Wincrt; m:string; function valide(message:string):boolean; if (message[i] in ['A'..'Z',' ']) then test:=true else test:=false; until (i>=length(message)) or not(test); valide:=test and (length(message) mod 2 = 0); procedure saisir(var message:string); write('donner une chaine à coder :'); readln(message); until valide(message); function crypter(message:string):string; i,e,x1,x2,yn1,yn2:integer; yc1,yc2:char; ch,ch1,aux,mcrypte,y1,y2:string; mcrypte:=''; for i:=1 to length(message) Do if i mod 2=1 Then ch:='('; if message[i] in ['A'..'Z'] Then str(ord(message[i])-65,aux) aux:='26'; ch:=ch+aux+','; if i mod 2=0 Then if message[i] in ['A'..'Z'] Then str(ord(message[i])-65,aux) else aux:='26'; ch:=ch+aux+')'; MEDDEB Mohamed Page 7
ch1:='('; val(copy(ch,2,pos(',',ch)-1),x1,e); val(copy(ch,pos(',',ch)+1,length(ch)- pos(',',ch)-1),x2,e); str((((11*x1)+(3*x2)) mod 27),y1); str((((7*x1)+(4*x2)) mod 27),y2); ch1:=ch1+y1+','+y2+')'; if y1='26' then yc1:=' ' else val(copy(ch1,2,pos(',',ch1)- 1),yn1,e); yc1:=chr(yn1+65); mcrypte:=mcrypte+yc1; if y2='26' then yc2:=' ' val(copy(ch1,pos(',',ch1)+1, length(ch1)-pos(',',ch1)-1),yn2,e); yc2:=chr(yn2+65); mcrypte:=mcrypte+yc2; crypter:=mcrypte; end. saisir(m); writeln(crypter(m)); sujet9: program bac_2017_25_mai_s9; uses wincrt; Type tableau=array [1..100] of string; tab=array[1..100] of real; TC:tableau; TN:tab; N:integer; procedure saisir(var n:integer); write('donner le nombre de participants :'); readln(n); until n in [5..100]; function verifgov(ch:string):boolean; if ch='' then test:=false if upcase(ch[i]) in ['A'..'Z'] then test:=true else test:=false; until not(test) or (i>=length(ch)); verifgov:=test and (length(ch)<=15); function verif(ch:string):boolean; test1,test2,testotal:boolean; if ch[i] in ['A'..'Z'] then test1:=true else test1:=false; until (i>=3) or not(test1); if test1=false then testotal:=false else MEDDEB Mohamed Page 8
if ch[i] in ['0'..'9'] then test2:=true else test2:=false; until not(test2) or (i>=length(ch)); testotal:=test1 and test2; verif:=(length(ch)=6) and testotal; function npr(tn:tab;n:integer):integer; i,s:integer; if TN[i]>=10 then s:=s+1; npr:=s; function ntpg(tn:tab;tc:tableau;gov:string;n:integer):integer; ch:string; i,j,s:integer; ch:=''; for j:=1 to 3 Do ch:=ch+upcase(gov[j]); if (ch=copy(tc[i],1,3)) then s:=s+1; ntpg:=s; function nprg(tn:tab;tc:tableau;gov:string;n:integer):integer; i,j,s:integer; ch:string; ch:=''; for j:=1 to 3 Do ch:=ch+upcase(gov[j]); s:=s+1; if (ch=copy(tc[i],1,3)) and (TN[i]>=10) then nprg:=s; procedure remplir(var TC:tableau;var TN:tab;n:integer); readln(tc[i]); Until verif(tc[i]); readln(tn[i]); until (TN[i]>=0) and (TN[i]<=20); procedure afficher(tc:tableau;tn:tab;n:integer); TRG,TRN:real; gov:string; TRN:=(npr(TN,n)/n)*100; writeln('le taux de reussite national est de ',TRN:5:2,' %'); readln(gov); until verifgov(gov); TRG:=((nprg(TN,TC,gov,n)/ntpg(TN,TC,gov,n))*100); writeln('le taux de reussite de ',gov,' est ',TRG:5:2,' %'); begin end. saisir(n); remplir(tc,tn,n); afficher(tc,tn,n); MEDDEB Mohamed Page 9
sujet10: program bac_2017_25_mai_s10; uses wincrt; Type tab=array [1..1000] of string; tableau=array [1..1000] of integer; ch:string; function valide(ch:string):boolean; test:=false; if ch<>'' Then if ch[i] in ['a'..'z'] then test:=true else test:=false; until (not(test)) or (i>=length(ch)); valide:=(test and (ch<>'') and (length(ch)>=2)); Procedure saisir(var ch:string); write('donner une chaine: '); readln(ch); until valide(ch); function existence(t:tab;ch:string;j:integer):boolean; if T[i]=ch then test:=true else test:=false; until (i>=j) or test; existence:=test; procedure afficher(ch:string); T:tab; Toc:tableau; i,j,k,l,s:integer; j:=0; for i:=1 to length(ch)-1 Do if (ch[i]<>ch[i+1]) Then if j<>0 Then if not(existence(t,ch[i]+ch[i+1],j)) Then s:=s+1; j:=j+1; T[j]:=ch[i]+ch[i+1]; End j:=j+1; T[j]:=ch[i]+ch[i+1]; if j<>0 Then for k:=1 to j Do for l:=1 to (length(ch)-1) Do if T[k]=(ch[l]+ch[l+1]) then ',T[k],' est ',Toc[k]); end. saisir(ch); afficher(ch); Toc[k]:=s; writeln('le nombre d''occurences de MEDDEB Mohamed Page 10