You are given a positive number x. Find the smallest positive integer number that has the sum of digits equal to x and all digits are distinct (unique).
Input
The first line contains a single positive integer t (1≤t≤50) — the number of test cases in the test. Then t test cases follow.
Each test case consists of a single integer number x (1≤x≤50).
Output
Output t answers to the test cases:
if a positive integer number with the sum of digits equal to x and all digits are different exists, print the smallest such number;
otherwise print -1.
Example
inputCopy
4
1
5
15
50
outputCopy
1
5
69
-1
手动打表,循环匹配
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<memory.h>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int a[maxn]={0,1,2,3,4,5,6,7,8,9,19,29,39,49,59,69,79,89,189,289,389,489,589,689,789,1789,2789,3789,4789,5789,6789,16789,26789,36789,46789,56789,156789,256789,356789,456789,1456789,2456789,3456789,13456789,23456789,123456789,-1,-1,-1,-1,-1,-1,-1,-1,-1};
void solve(){
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
cout<<a[n]<<endl;
}
}
int main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
solve();
return 0;
}