Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. class Arr{
  9. public:
  10. Arr(int n){
  11. this->n = n;
  12. this->a.resize(n);
  13. this->b.resize(n);
  14. }
  15. void input(){
  16. for (int i = 0;i < this->n; i++){
  17. this->a[i] = rand() % 100;
  18. }
  19. }
  20.  
  21.  
  22. int swap(){
  23. for (int i = 0; i < n; i++){
  24. this->b[i]=this->a[i];
  25. }
  26. for (int j = 0; j < n; j++)
  27. {
  28. if (j+k<n)
  29. {
  30. this->a[j]=this->b[(j+k)];
  31. }
  32. else
  33. {
  34. this->a[j]=0;
  35. }
  36. }
  37. return 0;
  38. }
  39.  
  40. void output(){
  41. for (int i = 0; i < this->n; i++){
  42. cout << this->a[i] << " ";
  43. }
  44. cout << "\n";
  45. }
  46. public:
  47. int n;
  48. int k;
  49. vector<int> a;
  50. vector<int> b;
  51.  
  52. };
  53.  
  54. int main(){
  55. Arr A(10);
  56. A.input();
  57. cout << "Vvedite col-vo sdvigov" << endl;
  58. cin >> A.k;
  59. A.output();
  60. A.swap();
  61. A.output();
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement