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. }
  34. }
  35. cout<<res<<endl;
  36. int r, revres = 0;
  37. while (res > 0)
  38. {
  39. r = res % 10;
  40. revres = revres*10 + r;
  41. res = res/10;
  42. }
  43. cout<<revres<<endl;
  44. }
  45. }
  46. return(0);
  47. }
Success #stdin #stdout 0.01s 5304KB
stdin
1
15
stdout
15
0