Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <limits.h>
- using namespace std;
- int main(){
- int a,n,i,v[50],g,K=0,s,f=INT_MAX,inceput=0,h;
- cin>>n;
- for(i=0;i<n;i++)
- cin>>v[i];
- inceput:{
- for(i=K;i<n;i++){
- a=v[i];s=0;
- while(a){s+=a%10;a=a/10;}
- if(s<f)f=s;
- }
- g=K;for(i=K;i<n;i++){
- a=v[i];s=0;
- while(a){s+=a%10;a=a/10;}
- if(s==f){swap(v[K],v[i]);K++;}
- if(K-g>2){
- for(i=g;i<K-1;i++){
- if(v[i]>v[i+1]){
- h=v[i];
- v[i]=v[i+1];
- v[i+1]=h;
- }}
- }
- if(i==n-1 && K<n)
- {f=INT_MAX;goto inceput;}
- }}
- for(i=0;i<n;i++)
- cout<<v[i]<<" ";
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement