|
- #include <bits/stdc++.h>
- using namespace std;
- int s=0;
- int a[10]={123,321,121,211,112,222,132,223,311,221};
- int qh(int n)
- {
- s = 0;// 此处应清零
- for(int i=0;n>0;i++)
- {
- s=s+n%10;
- n=n/10;
- }
- return s;
- }
- bool cmp(int x,int y)
- {
- if(qh(x)!=qh(y)) return qh(x)>qh(y);
- else return x>y;
- }
- int main()
- {
- sort(a,a+10,cmp);
- for(int i=0;i<=9;i++) cout<<a[i]<<" ";
- return 0;
- }
复制代码
|
|