Created
October 24, 2020 14:22
-
-
Save overnew/da33f41d5307ec7fa6a1b126a5757393 to your computer and use it in GitHub Desktop.
감소하는 수 정답 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<vector> | |
#include<cmath> | |
using namespace std; | |
int N; | |
int countDescendNum=9; | |
vector<long long> descendNumberSet; | |
void FindDescendNumber(int cnt){ | |
vector<long long>::iterator iter; | |
vector<long long> temp; | |
long long powNum = pow(10,cnt-1); | |
for(int i=1; i<10 ; ++i) | |
for(iter = descendNumberSet.begin(); iter<descendNumberSet.end() ;++iter ){ | |
if(*iter%10 < i){ | |
temp.push_back(powNum*i + *iter); | |
++countDescendNum; | |
if(countDescendNum == N){ | |
cout<< powNum*i + *iter<<'\n'; | |
return; | |
} | |
} | |
} | |
descendNumberSet = temp; | |
temp.clear(); | |
if(cnt<=10) | |
FindDescendNumber(cnt+1); | |
else | |
cout<<-1<<'\n'; | |
} | |
int main(){ | |
cin>>N; | |
vector<long long> nextDescNumSet ={0,1,2,3,4,5,6,7,8,9}; | |
descendNumberSet = nextDescNumSet; | |
if(N<10) | |
cout<<N<<'\n'; | |
else | |
FindDescendNumber(2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment