#include<bits/stdc++.h>
using namespace std;
int main()
{
int t, n, m, i, j, k = 1;
cin >> t;
while(t--)
{
cin >> n >> m;
vector<int>v(n);
for(i=0;i<n;i++)
{
cin >> v[i];
}
for(i=1;i<=m;i++)
{
char ch;
int a, b;
cin >> ch;
if(ch == 'S')
{
cin >> a;
for(j=0;j<n;j++)
v[j] = v[j] + a;
}
else if(ch == 'M')
{
cin >> a;
for(j=0;j<n;j++)
v[j] = v[j]*a;
}
else if(ch == 'D')
{
cin >> a;
for(j=0;j<n;j++)
v[j] = v[j]/a;
}
else if(ch == 'R')
{
reverse(v.begin(), v.end());
}
else if(ch == 'P')
{
cin >> a >> b;
swap(v[a], v[b]);
}
}
cout << "Case " << k++ << ":" << "\n";
for(i=0;i<n;i++)
{
cout << v[i];
if(i != n-1)
cout << " ";
}
cout << "\n";
}
return 0;
}
using namespace std;
int main()
{
int t, n, m, i, j, k = 1;
cin >> t;
while(t--)
{
cin >> n >> m;
vector<int>v(n);
for(i=0;i<n;i++)
{
cin >> v[i];
}
for(i=1;i<=m;i++)
{
char ch;
int a, b;
cin >> ch;
if(ch == 'S')
{
cin >> a;
for(j=0;j<n;j++)
v[j] = v[j] + a;
}
else if(ch == 'M')
{
cin >> a;
for(j=0;j<n;j++)
v[j] = v[j]*a;
}
else if(ch == 'D')
{
cin >> a;
for(j=0;j<n;j++)
v[j] = v[j]/a;
}
else if(ch == 'R')
{
reverse(v.begin(), v.end());
}
else if(ch == 'P')
{
cin >> a >> b;
swap(v[a], v[b]);
}
}
cout << "Case " << k++ << ":" << "\n";
for(i=0;i<n;i++)
{
cout << v[i];
if(i != n-1)
cout << " ";
}
cout << "\n";
}
return 0;
}
Comments
Post a Comment