1 solutions

  • 0
    @ 2025-12-3 16:59:04

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int x,t,a[1000],w=9,bj;
    int main()
    {
    	cin>>x;
    	while(x>0)
    	{
    		if(x>=w)	{a[t++]=w;x-=w;w--;}
    		else{
    			while(w>x) w--;			
    		}
    		if(w<0) {bj=1;break;}	
        }
    	if(bj==1) {cout<<-1;return 0;}	 
        for(int i=t-1;i>=0;i--)
        	cout<<a[i];
        return 0;
    }
    
    
    • 1

    Information

    ID
    938
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By