Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <vector>
- #include <algorithm>
- using namespace std;
- class Arr{
- public:
- Arr(int n){
- this->n = n;
- this->a.resize(n);
- this->b.resize(n);
- }
- void input(){
- for (int i = 0;i < this->n; i++){
- this->a[i] = rand() % 100;
- }
- }
- int swap(){
- for (int i = 0; i < n; i++){
- this->b[i]=this->a[i];
- }
- for (int j = 0; j < n; j++)
- {
- if (j+k<n)
- {
- this->a[j]=this->b[(j+k)];
- }
- else
- {
- this->a[j]=0;
- }
- }
- return 0;
- }
- void output(){
- for (int i = 0; i < this->n; i++){
- cout << this->a[i] << " ";
- }
- cout << "\n";
- }
- public:
- int n;
- int k;
- vector<int> a;
- vector<int> b;
- };
- int main(){
- Arr A(10);
- A.input();
- cout << "Vvedite col-vo sdvigov" << endl;
- cin >> A.k;
- A.output();
- A.swap();
- A.output();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement