codechef


/*Akshay Thakare*/
/*TE Comps*/
/*26-07-2014*/

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(int argv,char *argc)
{
int i,T,tmp,size,msize,temp2;
double in1,in2,temp1;

/*User inputs the number of test cases*/
scanf("%d",&T);
tmp = T;    //Saving the total test cases

while(tmp--)
{
/*Taking S and M from the user*/
scanf("%lf %lf",&in1,in2);

/*Calculating the size of maximum size*/
temp1 = in2;
size=0;
while(temp1!=0)
{
size+=1;
temp1 = temp1/10;
}

int max1;
double max;
msize=size;
temp1 = in2;

/*Calculating max possible outcome*/
while(size--)
{
temp2=(int)temp1%10;
switch(temp2)
{
case 0:max1=8;
break;
case 1:max1=9;
break;
case 2:max1=8;
break;
case 3:max1=9;
break;
case 4:max1=9;
break;
case 5:max1=9;
break;
case 6:max1=8;
break;
case 7:max1=9;
break;
case 8:max1=8;
break;
case 9:max1=9;
break;
default:max1=temp2;
break;
}
max = max1*pow(10,msize-size)+max;
temp2=temp2/10;
}
while(max>in2)
{
int temp3 = (int)max%(int)(10*pow(10,size-1));
int temp4 = (int)in2%(int)(10*pow(10,size-1));
if(temp3>=temp4&&temp3!=0)
{
max = max - 1*pow(10,size-1);
}
}
printf("%d",max);
}

return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s