fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int test,l,r,rev=0,sum=0;
  6. cin>>test;
  7. for(int i=0;i<test;i++)
  8. {
  9. cin>>l>>r;
  10. sum=0;
  11. for(int j=l;j<=r;j++)
  12. {
  13. rev = 0;//initialise the reversed number to zero for every j
  14. int temp = j;// store j in a temporary variable, we dont want to modify the loop counter variable
  15. while(temp>0)
  16. {
  17. rev = rev*10 + temp%10;
  18. temp/=10;
  19. }
  20. if(rev==j)//if it is a palindrome add it
  21. sum=rev+sum;
  22. }
  23. cout<<sum<<endl;
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 3464KB
stdin
1
1 1000
stdout
50040