#include <cstdio>
#include <algorithm>
const int inf = 0x3f3f3f3f;
int main () {
int T, x;
scanf ("%d", &T);
while (T--) {
scanf ("%d", &x);
int ans = inf;
for (int i = 0; i < (1 << 9); i++) {
int t = 0, s = 0;
for (int j = 0; j < 9; j++) {
if (i & (1 << j)) {
t = t + j + 1;
s = s * 10 + j + 1;
}
}
if (t == x) {
ans = std::min(ans, s);
}
}
printf ("%d\n", ans == inf ? -1 : ans);
}
return 0;
}
原文:https://www.cnblogs.com/chantmee/p/14167232.html