fork download
  1. program dreams;
  2. const MAXX = 1000;
  3. type elenco=array [1..MAXX] of Longint;
  4. var N, test, i, A, B, id , min, max,count, numeropal:Longint;
  5. pal : elenco;
  6.  
  7. (*A function to check if n is palindrome*)
  8.  
  9. function isPalindrome (x:Longint):boolean;
  10. var rev, ricordax:Longint;
  11. (* Find reverse of x*)
  12. begin
  13. rev:= 0; ricordax:=x;
  14. while x>=1 do
  15. begin
  16. rev := rev*10 + x mod 10;
  17. x:= x div 10;
  18. end;
  19. (*If x and rev are same, then x is palindrome*)
  20. if ricordax=rev then isPalindrome:=true
  21. else isPalindrome:=false;
  22. end;
  23.  
  24.  
  25. procedure generaPal;
  26. var j:Longint;
  27. begin
  28. j:=1;
  29. for i:=0 to Maxx do
  30. if isPalindrome(i)=true then begin pal[j]:=i; j:=j+1; end;
  31. numeropal:=j-1;
  32. end;
  33.  
  34.  
  35. Procedure ricercaLower (var w:elenco; target:longint); (*ritorna indice del valore minore/uguale a target *)
  36. var m,start,eend: longint;
  37.  
  38. begin
  39. start:=1; eend:=numeropal ; m:=-1;
  40. while start<=eend do
  41. begin
  42. m:=(start + eend) div 2;
  43. if w[m]<=target then begin id:=m; start:=m+1 end
  44. else if w[m]>target then eend:=m-1;
  45. end;
  46. end;
  47.  
  48. begin
  49. readln(N);
  50. generaPal;
  51. for test:=1 to N do
  52. begin
  53. readln(min, max);
  54. if isPalindrome(min)=true then count:=1 else count:=0;
  55. ricercaLower(pal, min);
  56. A:=id;
  57. ricercaLower(pal, max);
  58. B:=id;
  59. count:=count+B-A;
  60. writeln(count);
  61. end;
  62. end.
Success #stdin #stdout 0s 5324KB
stdin
5
11 22
111 222
1 1000
9 10
99 101
stdout
2
12
108
1
2