Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <vector>
- #include <Windows.h>
- #include <ctime>
- using namespace std;
- void perestanovka(int begin, vector<int>& end) {
- cout << "Перемешивание № " << begin << endl;
- for (int i = 0; i < end.size(); i++) {
- cout << end[i] << " ";
- }
- cout << endl;
- int temp = 0;
- for (int i = 0; i<end.size(); i++) {
- if (i + 1 == end[i]) {
- cout << "Совпадение с шаром № " << i + 1 << endl;
- temp = end[i];
- end[i] = end[begin - 1];
- end[begin - 1] = temp;
- }
- else {
- temp = end[i];
- end[i] = end[begin - 1];
- end[begin - 1] = temp;
- }
- }
- cout << endl << endl << endl;
- if (begin != end.size() - 1) {
- begin++;
- perestanovka(begin, end);
- }
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- srand(time(NULL));
- int temp = 0, n;
- bool once = true;
- cout << "Введите количество шаров" << endl;
- cin >> n;
- vector<int> balls(n, 0);
- for (int i = 0; i < n; i++) {
- while (balls[i] == 0) {
- temp = rand() % n + 1;
- for (int j = 0; j < n; j++) {
- if (temp == balls[j]) {
- once = false;
- }
- }
- if (once == true)
- balls[i] = temp;
- once = true;
- }
- }
- perestanovka(1, balls);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement