let's start Code

1133 - Array Simulation

1133 - Array Simulation

 #include<bits/stdc++.h>

using namespace std;


typedef long long ll;

//map<int , int>M;


int main()

{

     #ifndef ONLINE_JUDGE

    freopen("in.txt", "r", stdin);

    freopen("out.txt", "w", stdout);

  #endif


    int t;

    cin >> t;

    for(int cs = 1; cs <= t; cs++){

        int n,m;

    cin >> n >>m;

    int a[n+2];


    for(int i = 0; i < n; i++){

        cin >> a[i];

    }

    while(m--){

        char x;

        int val;

        cin >> x;

        if(x == 'S'){

            cin >> val;

            for(int i = 0; i < n; i++)

            a[i] += val;

            //sum +=vall;

        }

        else if(x == 'M'){

            cin >> val;

          for(int i = 0; i < n; i++)

            a[i] *= val;

            //mul *= val;

        }

        else if(x == 'D'){

            cin >> val;

           for(int i = 0; i < n; i++)

            a[i] /= val;

            //div *= val;

        }

        else if(x == 'R'){

            reverse(a, a+n);

        }

        else if(x == 'P'){

            int y,z;

            cin >> y >> z;

            swap(a[y], a[z]);

        }

        //for(int i =0; i < n; i++)cout << a[i]<< " ";

          //  cout << endl <<"------------"<<endl;

    }

    cout << "Case "<<cs << ":\n";

    for(int i = 0; i < n; i++){

        cout << a[i];

        if(i < n-1)cout << " ";

    }

    cout << endl;

 }

 return 0;

}

 


Share:

No comments:

Post a Comment

About

let's start CODE

Popular Posts