Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. void del(int *array, int *size, int id) {
  4. char move = 0;
  5. for (int i = 0; i < *size; ++i) {
  6. if (i == id) move = 1;
  7. else if (move == 1) array[i - 1] = array[i];
  8. }
  9. if (move == 1) --*size;
  10. }
  11. int lc(int chisl)
  12. {
  13. return chisl % 10;
  14. }
  15. void swap(unsigned long long *x, unsigned long long *y)
  16. {
  17. unsigned long long promezh = *x;
  18. *x = *y;
  19. *y = promezh;
  20. }
  21. int sum(int chisl)
  22. {
  23. int sum = 0;
  24. while (chisl != 0)
  25. {
  26. sum += chisl % 10;
  27. chisl /= 10;
  28. }
  29. return sum;
  30. }
  31. int maxcifr(int chisl)
  32. {
  33. int max = 0;
  34. while (chisl != 0)
  35. {
  36. if (max <= chisl % 10)
  37. {
  38. max = chisl % 10;
  39. }
  40. chisl /= 10;
  41. }
  42. return max;
  43. }
  44. int main()
  45. {
  46. int N;
  47. scanf("%i", &N);
  48. unsigned long long a[N];
  49. for (int i = 0; i < N; ++i)
  50. {
  51. scanf("%llu", &a[i]);
  52. }
  53. for (int i = 0 ; i < N - 1; i++)
  54. {
  55. for (int k = 0 ; k < N - i - 1 ; k++)
  56. {
  57. if (sum(a[k]) < sum(a[k + 1]))
  58. {
  59. swap(&a[k], &a[k + 1]);
  60. }
  61. }
  62. }
  63. for (int i = 0; i < N; ++i)
  64. {
  65. printf("%llu ", a[i]);
  66. }
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement