DilyaraL

Untitled

May 29th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6. const int n = 2;
  7.  
  8. int getMax(int arr[], int n)
  9. {
  10. int max = arr[0];
  11. for (int i = 1; i < n; i++)
  12. if (arr[i] > max)
  13. max = arr[i];
  14. return max;
  15. }
  16.  
  17. void countSort(int arr[],int exp)
  18. {
  19. int output[n], i, count[10] = { 0 };
  20. for (i = 0; i < n; i++)
  21. count[(arr[i] / exp) % 10]++;
  22. for (i = 1; i < 10; i++)
  23. count[i] += count[i - 1];
  24. for (i = n - 1; i >= 0; i--)
  25. {
  26. output[count[(arr[i] / exp) % 10] - 1] = arr[i];
  27. count[(arr[i] / exp) % 10]--;
  28. }
  29. for (i = 0; i < n; i++)
  30. arr[i] = output[i];
  31. }
  32.  
  33. void radixsort(int arr[], int n)
  34. {
  35. int exp, m;
  36. m = getMax(arr, n);
  37. for (exp = 1; m / exp > 0; exp *= 10)
  38. countSort(arr,exp);
  39. }
  40.  
  41. int power(int x, int y)
  42. {
  43. int p = 1;
  44. for (int i = 0; i < y; i++)
  45. p = p * x;
  46. return p;
  47. }
  48.  
  49. int main()
  50. {
  51.  
  52. ifstream f("Text.txt");
  53.  
  54. int m = 10,
  55. p = 2;
  56. int mass[n];
  57. for (int i = 0; i < n; i++)
  58. {
  59. mass[i] = 0;
  60. }
  61.  
  62. int ar;
  63. for (int i = 0; i < n; ++i)
  64. {
  65. for (int j = 0; j < m; ++j)
  66. {
  67. for (int k = p - 1; k >-1; k--)
  68. {
  69. f >> ar;
  70. mass[i] += j * (pow(10, k))*ar;
  71. }
  72. }
  73. }
  74.  
  75. for (int i = 0; i < n; i++)
  76. {
  77. cout << mass[i] << ' ';
  78. }
  79. cout << endl;
  80.  
  81. radixsort(mass, n);//цифровая
  82.  
  83. for (int i = 0; i < n; i++)
  84. {
  85. cout << mass[i] << ' ';
  86. }
  87. cout << endl<<endl;
  88. for (int i = 0; i < n; ++i)
  89. {
  90. for (int j = 0; j < m; ++j)
  91. {
  92. for (int k = p - 1; k >-1; k--)
  93. {
  94. if(mass[i]/power(10,k)%10==j)
  95. cout << 1 << ' ';
  96. else
  97. cout << 0 << ' ';
  98. }
  99. cout << endl;
  100. }
  101. cout << endl << endl;
  102. }
  103.  
  104. system("pause");
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment