0

Problem Description:

A contest closes in n days hh hours, mm minutes and ss seconds. Given two values of n, how many palindromes of the format nhhmmss would we find in the indicated interval?

A string is said to be palindrome if it reads the same backwards as forwards.

Constraints Input One line containing two integer n1 and n2, where n1<n2

Output One integer representing the number of palindromes in this countdown interval

Time Limit 3

Examples Example 1

Input

1 2

Output

472

Explanation

We need to check the numbers 1000000 through 2235959 including only numbers where the last 6 digits correspond to times. We find 472 such numbers: 1000001, 1001001, 1002001, 1003001, 1004001, ..., 2231322, 2232322, 2233322, 2234322, 2235322

Example 2

Input

0 2

Output

708

Explanation

There are 708 palindromes: 0000000, 0001000, 0002000, 0003000, 0004000, ..., 2231322, 2232322, 2233322, 2234322, 2235322

my code:

#include<iostream> 
using namespace std; 
long int count=0,hh=0,mm=0,ss=0;

int isPalindrome(int n) 
{ 
    
    int rev = 0; 
    for (int i = n; i > 0; i /= 10) 
        rev = rev*10 + i%10; 

    
    return (n==rev); 
} 

 
void countPal(int min, int max) 
{ 
    for (int i = min; i <= max;) 
    { int time;
     time=i*1000000+hh*10000+mm*100+ss;
      if (isPalindrome(time)) 
        count++;
     ++ss;
     if(ss>59)
     { ++mm; ss=0;}
     if(mm>59)
     {++hh; mm=0;}
     if(hh>23)
     { ++i; hh=0;}
       
    }
} 

 
int main() 
{   int n1,n2;
    cin>>n1>>n2;
    if(n1==0)
      n1++;
    countPal(n1,n2);
    cout<<count;
    return 0; 
}

for the test case 1, 2, i am getting 288 where as the answer is 472, where am i going wrong?

Geno C
  • 1,361
  • 3
  • 10
  • 25

0 Answers0