LightOj 1133 Array Simulation








#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,m,i,j,a[1000],b[1000],k,l,p;
    string s;
    //freopen("loj1133in.txt","r",stdin);
    //freopen("loj1133out.txt","w",stdout);
    cin>>t;
    for(i=1;i<=t;i++)
    {
        cin>>n>>m;
        for(j=0;j<n;j++)
        {
            cin>>a[j];
        }
        for(p=0;p<m;p++)
        {
            cin>>s;
            if(s.compare("S")==0)
            {
                cin>>k;
                for(j=0;j<n;j++)
                {
                   a[j]=a[j]+k;

                }
            }
            else if(s.compare("M")==0)
            {
                cin>>k;
                for(j=0;j<n;j++)
                {
                   a[j]=a[j]*k;
                }

            }
            else if(s.compare("D")==0)
            {
                cin>>k;
                for(j=0;j<n;j++)
                {
                   a[j]=a[j]/k;
                }

            }
            else if(s.compare("R")==0)
            {
                l=n-1;
                for(j=n;j>=0;j--)
                {
                   b[l-j]=a[j];
                }
                for(j=0;j<n;j++)
                {
                    a[j]=b[j];
                }

            }
            else
            {
                cin>>k>>l;
                swap(a[k],a[l]);

            }
        }

        printf("Case %d:\n",i);
        for(j=0;j<n;j++)
        {
            if(j!=n-1)
            {
                printf("%d ",a[j]);
            }
            else
            {
                 printf("%d",a[j]);
            }

        }

        printf("\n");




    }

    return 0;
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment