Advertisement
Horoshev

Untitled

Mar 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <locale>
  5. #include <Windows.h>
  6.  
  7. using namespace std;
  8.  
  9. int rows, cols, temp;
  10. const int s = 0;
  11.  
  12.  
  13. int main() {
  14. SetConsoleCP(1251);
  15. SetConsoleOutputCP(1251);
  16. setlocale(LC_ALL, "Russian");
  17.  
  18. bool prov = true;
  19. bool prov1 = true;
  20. string str, key;
  21. cout << "Enter your frase: ";
  22. getline(cin, str);
  23.  
  24. for (int i = 0; i < str.size(); i++) {
  25. str.at(i) = toupper(str.at(i));
  26. }
  27. while (prov) {
  28. str.find(' ');
  29. str.erase(str.find(' '), 1);
  30. if (str.find(' ') == string::npos) {
  31.  
  32. prov = false;
  33. }
  34. }
  35. cout << str << endl;
  36.  
  37. ///////////////////////////////////////////////////////////////////////////////
  38.  
  39. cout << "Введите кол-во строк: ";
  40. cin >> rows;
  41. rows++;
  42. cout << "Введите кол-во столбцов: ";
  43. cin >> cols;
  44. cout << "Введите ключ: ";
  45. cin >> key;
  46.  
  47. ////////////////////////////////////////////////////////////////////////////////////
  48.  
  49. char **mas = new char*[rows];
  50. for (int i = 0; i < rows; ++i) {
  51.  
  52. mas[i] = new char[cols];
  53.  
  54. }
  55. ////////////////////////////////////////////////////////////////////////////////
  56.  
  57. int k1 = 0;
  58. for (int i = 0; i<rows; ++i)
  59. for (int j = 0; j < cols; j++)
  60. if (k1 < key.length()) {
  61. mas[i][j] = key[k1];
  62. k1++;
  63. }
  64.  
  65. int k = 0;
  66. for (int i = 1; i<rows; ++i)
  67. for (int j = 0; j < cols; j++)
  68. if (k < str.length()) {
  69. mas[i][j] = str[k];
  70. k++;
  71. }
  72.  
  73. //////////////////////////////////////////////////////////////////////////////////
  74. for (int i = 0; i < cols; ++i)
  75. {
  76. for (int j = 0; j < cols - 1; ++j)
  77. {
  78. if (mas[0][j] > mas[0][j + 1])
  79. for (int s = 0; s<rows; s++)
  80. {
  81. temp = mas[s][j];
  82. mas[s][j] = mas[s][j + 1];
  83. mas[s][j + 1] = temp;
  84.  
  85. }
  86. }
  87. }
  88. ////////////////////////////////////////////////////////////////////////////////////////////
  89.  
  90. for (int i = 0; i<rows; i++) {
  91. for (int j = 0; j < cols; j++) {
  92. cout << mas[i][j] << " ";
  93. }
  94. cout << endl;
  95. }
  96. /////////////////////////////////////////////////////////////////////////////////
  97. cout << "\n\n\n\n";
  98. cout << "Демонстрация простого шифра перестановки: \n";
  99. for (int j = 0; j<cols; j++) {
  100. for (int i = 1; i<rows; i++)
  101. cout << mas[i][j];
  102. cout << " ";
  103. }
  104.  
  105.  
  106. cout << "\n\n\n\n\n\n";
  107.  
  108.  
  109. for(int i=0;i<key.size();++i)
  110. if (mas[0][i] == key[i]) {
  111. for (int s = 0; s<rows; s++)
  112. {
  113. temp = mas[s][i];
  114. mas[s][i] = mas[s][i + 1];
  115. mas[s][i + 1] = temp;
  116.  
  117. }
  118.  
  119.  
  120.  
  121.  
  122. }
  123.  
  124.  
  125.  
  126.  
  127. for (int i = 0; i<rows; i++) {
  128. for (int j = 0; j < cols; j++) {
  129. cout << mas[i][j] << " ";
  130. }
  131. cout << endl;
  132. }
  133.  
  134.  
  135. for (int j = 0; j<cols; j++) {
  136. for (int i = 1; i<rows; i++)
  137. cout << mas[i][j];
  138. cout << " ";
  139. }
  140.  
  141.  
  142.  
  143. ////////////////////////////////////////////////////////////////////////////////////
  144. cout << "\n\n\n\n";
  145. /*cout << "Демонстрация дешифровки простого шифра перестановки : \n";
  146.  
  147. for (int i = 1; i<rows; i++) {
  148. for (int j = 0; j<cols; j++)
  149. cout << mas[i][j];
  150.  
  151.  
  152. }
  153. cout << "\n";
  154. */
  155. ////////////////////////////////////////////////////////////////////////////////////////
  156. for (int i = 0; i < rows; i++) {
  157.  
  158. delete[] mas[i];
  159.  
  160. }
  161. delete[] mas;
  162. system("pause");
  163. return 0;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement