Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <chrono>
- using namespace std;
- int main()
- {
- string binary;
- cout << "Введите двоичное число: ";
- cin >> binary;
- auto start_time = chrono::high_resolution_clock::now();
- // выполнение сортировки
- bool swapped = true;
- while (swapped)
- {
- swapped = false;
- for (int i = 0; i < binary.length() - 1; i++)
- {
- if (binary[i] == '1' && binary[i+1] == '0')
- {
- swap(binary[i], binary[i+1]);
- swapped
- }
- }
- auto end_time = chrono::high_resolution_clock::now();
- auto execution_time = chrono::duration_cast<chrono::nanoseconds>(end_time - start_time).count();
- cout << "Отсортированное двоичное число: " << binary << endl;
- cout << "Время выполнения алгоритма: " << execution_time << " наносекунд" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement