Time Limit: 1 Sec Memory Limit: 128 MB
Description
God of Jinixin is a great god that his IQ is at the top of his team. In his computer,
there are many things that he is learning. Every day, he through learning to improve
his levels of knowledge. However, as an elder, God of Jinixin don't want to his learning
materials are read by persons who are "too young, too simple and sometimes naive"
for fear that they make a big news. So, God of Jinixin sets a password in his computer.
Certainly, his password also on the basis of the fundamental laws. The fundamental
laws are made by himself. The laws are that:
1. The password is made up by two n-bit numbers, they are separated by spaces,
and the sums of each digit of the two numbers are s.
2. They are the smallest number and the biggest number that satisfy condition 1.
3. When can't find the sum s of the n-bit numbers, the password is -1 -1.
4. God of Jinixin ensure that there is no leading zeros in the two numbers.
His password is just for fear that persons who are "too young,too simple and
sometimes naive" enter the computer. For you, the high IQ people, it's should not too
hard to decipher password.
Input
Input contains an integer T(1<=T<=100) in the first line, and then T lines follow.
Each line consists of a pair of integers n(0<n<=100) and s(0<=s<=900), separated by a
space.
Output
For each test case, you should output the password of God of Jinixin.
Sample Input
1
2 15
Sample Output
69 96
HINT
For a test case, the sum of two figures is 15,and the smallest number is 69 and
the biggest number is 96.
18
#include<stdio.h>
#include<string.h>
int main()
{
char a[1001],b[1001];
int t,s,n,m,i,j;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d%d",&n,&s);
if(s>n*9||(n>1&&s==0))
{printf("-1 -1\n");}
else{
memset(a,'0',sizeof(a));
memset(b,'0',sizeof(b));
m=s;
s=s-1;
a[0]='1';
j=0;
for(i=n-1;i>=0;i--)
{
if(s>9)
{
a[i]='9';
s=s-9;
}
else
{
a[i]=a[i]+s;
s=0;
}
if(m>9)
{
b[j]='9';
m=m-9;
}
else
{
b[j]=b[j]+m;
m=0;
}
j++;
}
a[n]='\0';
b[n]='\0';
printf("%s ",a);
printf("%s\n",b);
}
}
}
return 0;
}