Guest User

Untitled

a guest
Dec 10th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <string>
  4. #include <map>
  5. #include <functional>
  6.  
  7. using namespace std;
  8.  
  9. void Task5() {
  10. auto initialization = [](map<int, bool> *m, int count) {
  11. for (int i = 0; i < 10; ++i)
  12. m[i] = true;
  13. };
  14. /*For cut duplicate number in map*/
  15. auto cutting = [](map<int, bool> *m, int count, int value) {
  16. for (int i = 9; i > count; --i)
  17. m[i][value] = false;
  18. };
  19. /*For create copy map*/
  20. auto mould = [](map<int,bool> *m, map<int, bool> *m_copy, int count) -> map<int, bool>* {
  21. if (m_copy == nullptr) {
  22. map<int, bool> *m_copy = new map<int, bool>[10 - count];
  23. for (int i = 9; i > count; --i)
  24. for (int j = 0; j < 10; ++j)
  25. m_copy[i][j] = m[i][j]; /*<= here throw exepition*/
  26. return m_copy;
  27. }
  28. else {
  29. for (int i = 9; i > count; --i)
  30. for (int j = 0; j < 10; ++j)
  31. m[i][j] = m_copy[i][j];
  32. return m;
  33. }
  34. };
  35.  
  36. function<void(map<int, bool>*, int, int*)> recursive;
  37. recursive = [mould, cutting, &recursive](map<int, bool> *m, int count = 1, int *result = nullptr) -> void {
  38. if (count != 10) {
  39. for (int i = 0; i < 10; ++i) {
  40. static map<int, bool> *m_copy;
  41. if (i == 0)
  42. m_copy = mould(m, nullptr, 1);
  43. else {
  44. m = mould(m, m_copy, 1);
  45. if (m[count][i])
  46. result[count - 1] = i;
  47. else
  48. continue;
  49. }
  50. cutting(m, count, i);
  51. recursive(m, ++count, result);
  52. }
  53. }
  54. else {
  55. for (int i = 0; i < 10; ++i)
  56. cout << result[i];
  57. cout << endl;
  58. }
  59. };
  60. /*Create map
  61. int is digit(can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
  62. if digit is used bool will be false*/
  63. map<int, bool> *m = new map<int, bool>[10];
  64. for (int i = 0; i > 10; ++i)
  65. initialization(m, i);
  66. m[0][0] = false; //First number cant' be 0
  67. int *result = new int[10];
  68. recursive(m, 1, result);
  69. }
  70.  
  71. int main(){
  72. Task5();
  73. return 0;
  74. }
  75.  
  76. #include <cstdio>
  77. #include <iostream>
  78. #include <string>
  79. #include <map>
  80. #include <functional>
  81. #include <vector>
  82.  
  83. using namespace std;
  84.  
  85. auto end_task = []() {
  86. cout << endl << endl << endl;
  87. };
  88.  
  89. void initialization(vector<bool> &vec) {
  90. vec.reserve(10);
  91. for (int i = 0; i < 10; ++i)
  92. vec[i] = true;
  93. }
  94.  
  95. void cutting(vector<bool> *vec, int count, int value) {
  96. for (int i = 9; i > count; --i)
  97. vec[i][value] = false;
  98. }
  99.  
  100. vector<bool> *mould(vector<bool> *vec, vector<bool> *vec_copy, int count) {
  101. if (vec_copy == nullptr) {
  102. vector<bool> *vec_copy = new vector<bool>[10 - count];
  103. for (int i = 9; i > count; --i)
  104. for (int j = 0; j < 10; ++j)
  105. vec_copy[i][j] = vec[i][j];
  106. return vec_copy;
  107. }
  108. else {
  109. for (int i = 9; i > count; --i)
  110. for (int j = 0; j < 10; ++j)
  111. vec[i][j] = vec_copy[i][j];
  112. return vec;
  113. }
  114. }
  115.  
  116. void recursive(vector<bool> *vec, int count = 1, int *result = nullptr) {
  117. if (count != 10) {
  118. for (int i = 0; i < 10; ++i) {
  119. static vector<bool> *vec_copy;
  120. if (i == 0)
  121. vec_copy = mould(vec, nullptr, 1);
  122. else {
  123. vec = mould(vec, vec_copy, 1);
  124. if (vec[count][i])
  125. result[count - 1] = i;
  126. else
  127. continue;
  128. }
  129. cutting(vec, count, i);
  130. recursive(vec, ++count, result);
  131. }
  132. }
  133. else {
  134. for (int i = 0; i < 10; ++i)
  135. cout << result[i];
  136. cout << endl;
  137. }
  138. }
  139.  
  140. void Task5() {
  141. vector<bool> *vec = new vector<bool>[10];
  142. for (int i = 0; i > 10; ++i)
  143. initialization(vec[i]);
  144. vec[0][0] = false;
  145. int *result = new int[10];
  146. recursive(vec, 1, result);
  147. end_task();
  148. }
  149.  
  150.  
  151. int main(){
  152. Task5();
  153. return 0;
  154. }
Add Comment
Please, Sign In to add comment