shichemt

Correction BAC 2013 a 11h

May 27th, 2013
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. { BAC 2013 -- 11h -- Section Scientifique
  2. Enonce: http://goo.gl/Y7C6N
  3. NB: Le programme ne fonctionne pas avec quelques exemples, car l'intervalle des entiers est limitée
  4. }
  5.  
  6. program bac2013v11;
  7. uses wincrt;
  8. var i,e:integer; ch:string;  trv1,trv2:boolean; a,n,x:longint;
  9. procedure saisir(var n:longint);
  10. begin
  11. repeat
  12. writeln('Donner n');
  13. readln(n);
  14. until(n>=10);
  15. end;
  16.  
  17. procedure inverse (var ch:string);
  18. var i,j:integer;
  19. procedure permut (var x,y:char);
  20. var aux:char;
  21. begin
  22. aux := x;
  23. x := y;
  24. y := aux;
  25. end;
  26.  
  27. begin
  28. i:=0;
  29. j:=length(ch);
  30. repeat
  31. i:=i+1;
  32. permut(ch[i],ch[j]);
  33. j:=j-1;
  34. until(j=i);
  35. end;
  36.  
  37. function pali (var ch:string):boolean;
  38. var debut,n:integer; trv:boolean;
  39. begin
  40. debut:=1;
  41. n:= length(ch);
  42. repeat
  43. debut:=debut+1;
  44. n:=n-1;
  45.  
  46. until((debut>n) or (ch[n] <> ch[debut]));
  47. if (ch[n] <> ch[debut]) then trv:=false
  48. else trv:=true;
  49.  
  50. pali:= trv;
  51. end;
  52.  
  53. begin
  54.  
  55. saisir(n);
  56. a:=n;
  57. i:=0;
  58. repeat
  59. i:=i+1;
  60. str(a,ch);
  61. if (pali(ch)) then
  62. trv1:=true
  63. else
  64. begin
  65. inverse(ch);
  66. val(ch,x,e);
  67. a:=a+x;
  68. str(a,ch);
  69. trv1:=((pali(ch)) and (i<=10));
  70. trv2:=((pali(ch)=false) and (i=11));
  71. end;
  72. until((trv1) or (trv2));
  73. if (trv1) then writeln('Cette suite est palindromique')
  74. else if(trv2) then writeln('Le calcul de 11 termes ne donne pas une suite palidromique pour ce nombre.')
  75.  
  76.  
  77. end.
Advertisement
Add Comment
Please, Sign In to add comment