题目
题目链接
题解考点:
- 获取一个数的每一位上的数
- 实现从大到小的排序
注意:
- 高位为0的情况中,0也要进行排序
#include
using namespace std;
int n, cnt, a[5], b[5], aa, bb, ans;
bool cmp(int x, int y) {return x>y;}
int main()
{
cin>>n;
while(n!=6174) {
int x = n;
cnt = aa = bb = 0;
while(x) {
++cnt;
a[cnt] = b[cnt] = x%10;
x/=10;
}
if(cnt!=4) ++cnt, a[cnt] = b[cnt] = 0;
sort(a+1, a+5, cmp);
sort(b+1, b+5);
for(int i = 1;i
关注
打赏