Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream fin ("sortcif.in");
- ofstream fout ("sortcif.out");
- int v[101],cif[101],n,aux;
- bool ok=1;
- int pcif(int a)
- {
- long long s=0;
- while(a)
- {
- s+=a%10;
- a/=10;
- }
- return s;
- }
- int main()
- {
- fin>>n;
- for(int i=1 ; i<=n ; i++)
- {
- fin>>v[i];
- cif[i]=pcif(v[i]);
- }
- do
- {
- ok=0;
- for(int i=1 ; i<=n ; i++)
- {
- if(cif[i]<cif[i+1])
- {
- ok=1;
- aux=v[i];
- v[i]=v[i+1];
- v[i+1]=aux;
- aux=cif[i];
- cif[i]=cif[i+1];
- cif[i+1]=aux;
- }
- }
- }while(ok);
- for(int i=n ; i>=1 ; i--)
- fout<<v[i]<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement