Advertisement
Horoshev

Untitled

Mar 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 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;
  10. int cols;
  11.  
  12.  
  13. int main() {
  14. SetConsoleCP(1251);
  15. SetConsoleOutputCP(1251);
  16. setlocale(LC_ALL, "Russian");
  17.  
  18. bool prov = true;
  19.  
  20. string str;
  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. cout << "Введите кол-во столбцов: ";
  42. cin >> cols;
  43.  
  44. char **mas = new char*[rows];
  45. for (int i = 0; i < rows; ++i) {
  46.  
  47. mas[i] = new char[cols];
  48.  
  49. }
  50. ////////////////////////////////////////////////////////////////////////////////
  51.  
  52. int k = 0;
  53. for (int i = 0; i<rows; ++i)
  54. for (int j = 0; j < cols; j++)
  55. if (k < str.length()+1 ) {
  56. mas[i][j] = str[k];
  57. k++;
  58. }
  59.  
  60.  
  61.  
  62. for (int i = 0; i<rows; i++) {
  63. for (int j = 0; j < cols; j++) {
  64. cout << mas[i][j]<<" ";
  65. }
  66. cout << endl;
  67. }
  68. /////////////////////////////////////////////////////////////////////////////////
  69. cout << "\n\n\n\n";
  70. cout << "Демонстрация простого шифра перестановки: \n";
  71. for (int j = 0; j<cols; j++) {
  72. for (int i = 0; i<rows; i++)
  73. cout << mas[i][j];
  74. cout << " ";
  75. }
  76.  
  77.  
  78. ////////////////////////////////////////////////////////////////////////////////////
  79. cout << "\n\n\n\n";
  80. cout << "Демонстрация дешифровки простого шифра перестановки : \n";
  81.  
  82. for (int i = 0; i<rows; i++) {
  83. for (int j = 0; j<cols; j++)
  84. cout << mas[i][j];
  85.  
  86.  
  87. }
  88. cout << "\n";
  89.  
  90. ////////////////////////////////////////////////////////////////////////////////////////
  91. for (int i = 0; i < rows; i++) {
  92.  
  93. delete[] mas[i];
  94.  
  95. }
  96. delete[] mas;
  97. system("pause");
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement