Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { BAC 2013 -- 11h -- Section Scientifique
- Enonce: http://goo.gl/Y7C6N
- NB: Le programme ne fonctionne pas avec quelques exemples, car l'intervalle des entiers est limitée
- }
- program bac2013v11;
- uses wincrt;
- var i,e:integer; ch:string; trv1,trv2:boolean; a,n,x:longint;
- procedure saisir(var n:longint);
- begin
- repeat
- writeln('Donner n');
- readln(n);
- until(n>=10);
- end;
- procedure inverse (var ch:string);
- var i,j:integer;
- procedure permut (var x,y:char);
- var aux:char;
- begin
- aux := x;
- x := y;
- y := aux;
- end;
- begin
- i:=0;
- j:=length(ch);
- repeat
- i:=i+1;
- permut(ch[i],ch[j]);
- j:=j-1;
- until(j=i);
- end;
- function pali (var ch:string):boolean;
- var debut,n:integer; trv:boolean;
- begin
- debut:=1;
- n:= length(ch);
- repeat
- debut:=debut+1;
- n:=n-1;
- until((debut>n) or (ch[n] <> ch[debut]));
- if (ch[n] <> ch[debut]) then trv:=false
- else trv:=true;
- pali:= trv;
- end;
- begin
- saisir(n);
- a:=n;
- i:=0;
- repeat
- i:=i+1;
- str(a,ch);
- if (pali(ch)) then
- trv1:=true
- else
- begin
- inverse(ch);
- val(ch,x,e);
- a:=a+x;
- str(a,ch);
- trv1:=((pali(ch)) and (i<=10));
- trv2:=((pali(ch)=false) and (i=11));
- end;
- until((trv1) or (trv2));
- if (trv1) then writeln('Cette suite est palindromique')
- else if(trv2) then writeln('Le calcul de 11 termes ne donne pas une suite palidromique pour ce nombre.')
- end.
Advertisement
Add Comment
Please, Sign In to add comment