Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //napishete funkciq sorts s masiv ot long long purvo da gi podredi namalqvashto po sumata ot ciftire
- //pri ednakva suma ot cifrite rastqshto po golemina
- //interfeisa void sortS(int n,long long a[])
- //vhod {556,918,6,13,402,51}
- //izhod {918,556,6,51,402,13}
- void input (int n,long long a[])
- {
- for(int i=0;i<n;i++)
- cin>>a[i];
- }
- void output(int n,long long a[])
- {
- for(int i=0;i<n;i++)
- cout<<a[i]<<' ';
- }
- int Sum(long long a)
- {
- int s=0;
- while (a)
- {
- s=s+a%10;
- a=a/10;
- }
- return s;
- }
- void sortS(int n,long long a[])
- {
- int i,j,temp;
- for (i=0;i<n-1;i++)
- {
- for (j=1;j<n-i;j++)
- if(Sum(a[j-1])<Sum(a[j]))
- {
- temp=a[j-1];
- a[j-1]=a[j];
- a[j]=temp;
- continue;
- }
- if(Sum(a[j-1])==Sum(a[j]) && a[j-1]>a[j])
- {
- temp=a[j-1];
- a[j-1]=a[j];
- a[j]=temp;
- }
- }
- }
- int main()
- {int n;
- cin>>n;
- long long a[100];
- input(n,a);
- output(n,a);
- cout<<endl;
- sortS(n,a);
- output(n,a);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement