Thursday, July 30, 2015

1133 - Array Simulation

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    long T,n,m,i,arry[120],second,third,temp[120],c=1;
    char first;
//    freopen("check.txt","r",stdin);
    scanf("%ld",&T);
    while(T--)
    {
        scanf("%ld%ld",&n,&m);
        for(i=0; i<n; i++)
            scanf("%ld",&arry[i]);
        while(m--)
        {
            cin >> first;
 
            if(first == 'S' || first == 'M' || first == 'D')
            {
                scanf("%ld",&second);
                if(first == 'S')
                {
                    for(i=0; i<n; i++)
                        arry[i] += second;
                }
                else if(first == 'M')
                {
                    for(i=0; i<n; i++)
                        arry[i] *= second;
                }
                else if(first == 'D')
                {
                    for(i=0; i<n; i++)
                        arry[i] /= second;
                }
            }
            else if(first == 'R')
            {
                int k=0;
                for(i=n-1; i>=0; i--)
                    temp[k++]=arry[i];
                for(i=0; i<n; i++)
                    arry[i]=temp[i];
            }
            else if(first == 'P')
            {
                int t;
                scanf("%ld%ld",&second,&third);
                t=arry[second];
                arry[second]=arry[third];
                arry[third]=t;
            }
 
        }
        printf("Case %ld:\n",c++);
        for(i=0; i<n; i++)
        {
            if(i)
                printf(" ");
            printf("%ld",arry[i]);
        }
        printf("\n");
    }
    return 0;
}

No comments:

Post a Comment

Triathlon

Triathlon - CodeChef # include < bits/stdc++.h > using namespace std ; # define fi first # define se second # define mp ...