daily pastebin goal
46%
SHARE
TWEET

ani

a guest Feb 20th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. //napishete funkciq sorts s masiv ot long long purvo da gi podredi namalqvashto po sumata ot ciftire
  4. //pri ednakva suma ot cifrite rastqshto po golemina
  5. //interfeisa void sortS(int n,long long a[])
  6. //vhod {556,918,6,13,402,51}
  7. //izhod {918,556,6,51,402,13}
  8. void input (int n,long long a[])
  9. {
  10.     for(int i=0;i<n;i++)
  11.         cin>>a[i];
  12.     }
  13. void output(int n,long long a[])
  14. {
  15.     for(int i=0;i<n;i++)
  16.         cout<<a[i]<<' ';
  17.     }
  18. int Sum(long long a)
  19. {
  20.     int s=0;
  21.     while (a)
  22.     {
  23.         s=s+a%10;
  24.         a=a/10;
  25.     }
  26.     return s;
  27. }
  28. void sortS(int n,long long a[])
  29. {
  30.     int i,j,temp;
  31.     for (i=0;i<n-1;i++)
  32.     {
  33.         for (j=1;j<n-i;j++)
  34.             if(Sum(a[j-1])<Sum(a[j]))
  35.         {
  36.             temp=a[j-1];
  37.             a[j-1]=a[j];
  38.             a[j]=temp;
  39.             continue;
  40.         }
  41.         if(Sum(a[j-1])==Sum(a[j]) && a[j-1]>a[j])
  42.         {
  43.             temp=a[j-1];
  44.             a[j-1]=a[j];
  45.             a[j]=temp;
  46.         }
  47.     }
  48. }
  49. int main()
  50. {int n;
  51. cin>>n;
  52. long long a[100];
  53. input(n,a);
  54. output(n,a);
  55. cout<<endl;
  56. sortS(n,a);
  57. output(n,a);
  58. return 0;
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top