Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. void myCript(int m1, int l1, char* arr);
  5. int main()
  6. {
  7. char str[101];
  8. int M, L;
  9. int i = 0, counter = 0;
  10. bool flag = true;
  11. cin.getline(str, 101);
  12.  
  13. while (true)
  14. {
  15. cout << "Enter M" << endl;
  16. cin >> M;
  17. if (cin.fail())
  18. {
  19. cout << "Error! Try again";
  20. cin.clear();
  21. cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
  22. cin >> M;
  23. }
  24.  
  25. else if (M > 20)
  26. {
  27. cout << "Error! Try again";
  28. cin.clear();
  29. cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
  30. cin >> M;
  31. }
  32. else
  33. {
  34. break;
  35. }
  36.  
  37. }
  38.  
  39. while (true)
  40. {
  41. cout << "Enter L" << endl;
  42. cin >> L;
  43. if (cin.fail())
  44. {
  45. cout << "Error! Try again";
  46. cin.clear();
  47. cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
  48. cin >> L;
  49. }
  50.  
  51. else if (L > 100)
  52. {
  53. cout << "Error! Try again";
  54. cin.clear();
  55. cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
  56. cin >> L;
  57. }
  58. else
  59. {
  60. break;
  61. }
  62. }
  63.  
  64. while (str[i] != '\0')
  65. {
  66. i++;
  67. }
  68. for (int j = 0; j < i; j++)
  69. {
  70. if (str[j] < 32 || str[j] > 126)
  71. {
  72. flag = false;
  73. }
  74. }
  75. if (!flag)
  76. {
  77. cout << "invalid symbols" << endl;
  78. }
  79.  
  80. cout << str;
  81.  
  82. system("pause");
  83.  
  84. return 0;
  85. }
  86. void myCript(int m, int l, char* arr)
  87. {
  88. int counter = 0;
  89. while (arr[counter] != '\0')
  90. {
  91. counter ++ ;
  92. }
  93. for (int i = 0; i < counter; i++)
  94. {
  95. if (i + l > counter )
  96. {
  97. arr[i] = arr[abs(counter - i - l)];
  98. }
  99. else
  100. {
  101. arr[i + l] = arr[i];
  102.  
  103. }
  104. }
  105. for (int j = 0; j < counter; j++)
  106. {
  107. arr[j] = arr[j] + m;
  108. }
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement