Problem Description
"It's possible for all the digits displayed on a digital clock in the hours:minutes format to be identical. The time shown above (3:33) is an example of such a situation. Other examples are 2:2 and 1:11. Note that the digits of 33:33 are identical, but it is not a valid time on a usual digital clock.
The above example was for a usual 24-hour format digital clock. Let's consider a more general clock, where an hour lasts M minutes and a day lasts H hours (therefore, the clock can show any number of hours between 0 and H-1, inclusive, and any number of minutes between 0 and M-1, inclusive). Both the hours and the minutes are shown without leading zeroes in decimal notation and their separator (e.g., ':') doesn't matter.
Can you tell how many minutes during a day will the digital clock have identical digits displayed on it?"CODING ARENA
#include <stdio.h>
int min(int x,int y)
{
if(x<y)
return x;
else
return y;
}
int main()
{
int t,n,m,a,b,s;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
a=(n-1)/11;
b=(m-1)/11;
s=min(min(10,m),min(10,n))+min(a,m-1)+min(n-1,b)+min(a,b);
printf("%d\n",s);
}
return 0;
}
Test Case 1
Input (stdin)6 24 60 34 50 10 11 10 12 11 11 1 1
Expected Output19 20 10 11 10 1
Test Case 2
Input (stdin)6 30 60 34 40 11 11 12 10 10 11 1 2
Expected Output19 19 10 11 10 1
No comments:
Post a Comment