Advertisement
Guest User

Krisa

a guest
Feb 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. void swap(long long *xp, long long *yp)
  5. {
  6.     int temp = *xp;
  7.     *xp = *yp;
  8.     *yp = temp;
  9. }
  10. int sevenCount(long long arrN)
  11. {
  12.     int count = 0;
  13.     while (arrN > 0)
  14.     {
  15.         int digit = arrN%10;
  16.         if(digit == 7)
  17.         {
  18.             count++;
  19.         }
  20.         arrN /= 10;
  21.     }
  22.     return count;
  23. }
  24. void MoDbubbleSort(long long arr[], int n)
  25. {
  26.    int i, j;
  27.    for (i = 0; i < n-1; i++)
  28.        for (j = 0; j < n-i-1; j++)
  29.            if (sevenCount(arr[j]) > sevenCount(arr[j+1]))
  30.               swap(&arr[j], &arr[j+1]);
  31. }
  32.  
  33. void bubbleSort(long long arr[], int n)
  34. {
  35.    int i, j;
  36.    for (i = 0; i < n-1; i++)
  37.        for (j = 0; j < n-i-1; j++)
  38.            if (arr[j] > arr[j+1])
  39.               swap(&arr[j], &arr[j+1]);
  40. }
  41.  
  42. void printArray(long long arr[], int size)
  43. {
  44.     int i;
  45.     for (i=0; i < size; i++)
  46.         cout<<arr[i]<<" ";
  47. }
  48. int main()
  49. {
  50.     long long arr[] = {17, 17377, 41, 973, 427, 277};
  51.     int n = sizeof(arr)/sizeof(arr[0]);
  52.     bubbleSort(arr, n);
  53.     MoDbubbleSort(arr, n);
  54.     printArray(arr, n);
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement