题意:给位数和位数和 求符合要求的最大值和最小值
//想法都有了,可是却没有做粗来(你484傻啊?? ?(?_?)? ??)
Description
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Sample Input
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1
1 #include<stdio.h> 2 #include<math.h> 3 #include<algorithm> 4 using namespace std; 5 int main() 6 { 7 int m,s,s1,s2,i; 8 int a[101],b[101]; 9 while(~scanf("%d %d",&m,&s)) 10 { 11 int sum=0; 12 if(m==1&&s==0) 13 puts("0 0"); 14 else if(s>9*m||s==0) 15 puts("-1 -1"); 16 else 17 { 18 s1=s2=s; 19 for(i=m-1;i>=1;i--) 20 { 21 if(s1>9) 22 { 23 a[i]=9; 24 s1-=9; 25 } 26 else if(s1>1) 27 { 28 a[i]=s1-1; 29 s1=1; 30 } 31 else if(s1==1) 32 a[i]=0; 33 } 34 a[0]=s1; 35 for(i=0;i<m;i++) 36 { 37 if(s2>9) 38 { 39 b[i]=9; 40 s2-=9; 41 } 42 else if(s2>0) 43 { 44 b[i]=s2; 45 s2=0; 46 } 47 else if(s2==0) 48 b[i]=0; 49 } 50 for(i=0;i<m;i++) 51 printf("%d",a[i]); 52 printf(" "); 53 for(i=0;i<m;i++) 54 printf("%d",b[i]); 55 printf("\n"); 56 } 57 } 58 return 0; 59 }