fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int t, x, sum;
  7. cin>>t;
  8. while (t--)
  9. {
  10. cin>>x;
  11. if (x > 45)
  12. {
  13. cout<<-1<<endl;
  14. continue;
  15. }
  16. if (x <= 9)
  17. {
  18. cout<<x<<endl;
  19. continue;
  20. }
  21. else
  22. {
  23. int arr[] = {9, 8, 7, 6, 5, 4, 3, 2, 1};
  24. int res = 0;
  25. sum = 0;
  26. for (int i=0; i<10; i++)
  27. {
  28. if ((sum+arr[i]) <= x)
  29. {
  30. sum += arr[i];
  31. res = res * 10 + arr[i];
  32. //cout<<res<<endl;
  33. if (sum == x)
  34. break;
  35. }
  36. }
  37. //cout<<res<<" $$$$"<<endl;
  38. int r, revres = 0;
  39. while (res > 0)
  40. {
  41. r = res % 10;
  42. revres = revres*10 + r;
  43. res = res/10;
  44. }
  45. cout<<revres<<endl;
  46. }
  47. }
  48. return(0);
  49. }
Success #stdin #stdout 0.01s 5480KB
stdin
4
1
5
15
50
stdout
1
5
69
-1