/**
对于任意的5位数,求出其降序数
**/
#include <iostream>
using namespace std;
class NUM
{
public:
NUM(int x,int);
void decrease();
void show();
private:
int n,m; //n为输入的那个整数,m为输入整数的位数
int a[20];
};
NUM::NUM(int x,int y){
for(int i=0;i<x;i++){
a[i]=0;
}
m=x;
n=y;
}
void NUM::decrease(){
int i=0;
int y=n;
int num=m;
//将整数各位放入数组
while(y){
a[i]=y%10;
y=y/10;
i++;
}
//冒泡法排序
for(int j=0;j<num-1;j++){
for(int k=0;k<num-1-j;k++){
if(a[k]<a[k+1]){
int tmp=a[k];
a[k]=a[k+1];
a[k+1]=tmp;
}
}
}
}
void NUM::show(){
cout<<"n="<<n<<endl;
for(int i=0;i<m;i++){
cout<<a[i];
}
}
int main(){
NUM num(5,68548);
num.decrease();
num.show();
return 0;
}