1133 – Array Simulation

Problem Link

<Source Code>

#include<bits/stdc++.h>
using namespace std;
int a[10000],b[10000];
char c;

int main()
{
int t,n,j,o,m,i,add,d;
cin>>t;
for(o=1;o<=t;o++)
{
cin>>n>>m;
memset(a,0,sizeof(a));
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<m;i++)
{
cin>>c;
if(c==’S’)
{cin>>add;
for(j=0;j<n;j++)
a[j]+=add;
}
else if(c==’M’)
{
cin>>d;
for(j=0;j<n;j++)
a[j]*=d;

}
else if(c==’R’)
{
for(j=0;j<=(n-1)/2;j++)
swap(a[n-j-1],a[j]);
}
else if(c==’D’)
{
cin>>d;
for(j=0;j<n;j++)
a[j]=a[j]/d;
}
else{
int x,y;
cin>>x>>y;
swap(a[x],a[y]);
}
}

printf(“Case %d:\n”,o);
for(j=0;j<n-1;j++)
{printf(“%d “,a[j]);
}
cout<<a[n-1];
cout<<endl;

}
return 0;
}

 

Advertisements

About waprogramming

I am in CSE,from CUET
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s