#include <algorithm>
#include <string>
#include <iostream>
int main()
{
std::string s = "acb"; // что переставляем
std::sort(s.begin(), s.end());
do
{
std::cout << s << std::endl;
} while(std::next_permutation(s.begin(), s.end()));
}
#include <iostream>
#include <set>
#include <string>
#include <cstring>
using namespace std;
int factorial(int i)
{
if (i == 0) return 1;
else return i*factorial(i - 1);
}
int main()
{
char chars[] = "fdsgcba";
// получаем размер массива
int size = sizeof(chars) / sizeof(chars[0]) - 1; // -1 для отсечения \0 (окончания строки). иначе он будет учитыватся в переборе.
char temp; // временная переменная для обмена элементов местами
int count = 0; // счетчик перебора
// Сортировка массива пузырьком
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (chars[j] > chars[j + 1]) {
// меняем элементы местами
temp = chars[j];
chars[j] = chars[j + 1];
chars[j + 1] = temp;
++count;
}
}
}
// Вывод отсортированного массива на экран
for (int i = 0; i < size; i++) {
cout << chars[i] << " ";
}
cout << endl;
cout << "Count: " << count << endl;
cout << "O(n!*n): " << factorial(size) * size << endl;
return 0;
}
a b c d f g s
Count: 17
O(n!*n): 35280
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.