Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <cmath>
- #include <iostream>
- using namespace std;
- int main(){
- //setlocale(LC_ALL, "Russian");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- string s;
- cout << "Текст: ";
- getline(cin, s);
- while (sqrt(s.length()) != (int)sqrt(s.length()) || (int)sqrt(s.length()) % 2 == 0)
- s += ' ';
- int n = (int)sqrt(s.length());
- char a[n][n];
- for (int i = 0; i < s.length(); ++i){
- if (i && i % n == 0)
- cout << endl;
- a[i/n][i%n] = s[i];
- cout << a[i/n][i%n] << ' ';
- }
- cout << endl << "Зашифровано: '";
- int i = n / 2, j = i, imax = i + 1, imin = i - 1, jmax = j + 1, jmin = j - 1;
- do{
- while (j != jmin)
- cout << a[i][j--];
- jmin--;
- while (i != imax)
- cout << a[i++][j];
- imax++;
- while (j != jmax)
- cout << a[i][j++];
- jmax++;
- while (i != imin)
- cout << a[i--][j];
- imin--;
- while (j != jmin)
- cout << a[i][j--];
- }while (i > 0 || j > 0);
- cout << "'\n";
- cin.get(); return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement