特例真多
#include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<vector> #include<utility> #include<map> #include<set> #include<queue> #include<cmath> using namespace std; typedef long long int int64; int main() { int n, sum; scanf("%d %d", &n, &sum); if(sum == 0 and n == 1){ puts("0 0"); return 0; } if(sum == 0 or sum > n*9){ puts("-1 -1"); return 0; } int psum = sum; int arr[101] = {0}; arr[n-1] = 1; psum--; for(int lx = 0;lx < n;lx++){ if(psum >= 9){ arr[lx] += 9; psum -= 9; }else{ arr[lx] += psum; psum = 0; } } for(int lx = n-1;lx >= 0;lx--) printf("%d", arr[lx]); printf(" "); for(int lx = 0;lx < sum/9;lx++) printf("9"); if(sum/9<n){ printf("%d", sum%9); for(int lx = sum/9+1;lx < n;lx++) printf("0"); } printf("\n"); return 0; }
沒有留言:
張貼留言