Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <conio.h>
- using namespace std;
- #define TAB '\t';
- void main()
- {
- srand(time(NULL));
- const int sz = 5;
- int alpha[sz];
- int tmp, m, b = 0;
- char snsr = 0;
- int psh = (setlocale(0, ""), cout << "Введите количество элементов для сдвига: ", cin >> psh, cout << endl, psh);
- for (int i = 0; i < sz; i++)
- cout << (alpha[i] = i) << TAB;
- while (snsr != 27)
- {
- snsr = getch();
- system("cls");
- if (snsr == 65 || snsr == 97) m = -1; // A
- if (snsr == 68 || snsr == 100) m = 1; // D
- if (m == -1)
- {
- for (int i = 0; i < psh; ++i)
- {
- for (int j = b; j < sz - 1; ++j)
- {
- tmp = alpha[j];
- alpha[j] = alpha[j + 1];
- alpha[j + 1] = tmp;
- }
- }
- }
- else
- {
- for (int i = 0; i < psh; ++i)
- {
- for (int j = sz - 1; j > b; --j)
- {
- tmp = alpha[j];
- alpha[j] = alpha[j - 1];
- alpha[j - 1] = tmp;
- }
- }
- }
- cout << endl;
- for (int i = 0; i < sz; i++)
- cout << alpha[i] << TAB;
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement