1133 - Array Simulation (工业题)

I am retired now, so, no work, a lot of time to spare and alot of problems to share. Well, finally I am thinking of the old days when Iwas a solver. But now I am stuck with a tough problem that I want to share withyou.

Given an array and some operations on the array, you have toprint the final state of the array. Say, the array is a[], the size is nand indexed from 0 to n-1.

The operations are:

1.      'S D'. Dis an integer. D will be added with all the elements of the array.

2.      'M D'. Dis an integer. All the elements of the array will be multiplied by D.

3.      'D K'. Kis a non zero integer. All the elements of the array will be divided by K(integer division).

4.      'R'. Itmeans reverse. It will reverse the elements of the array.

5.      'P Y Z'. Yand Z are integers. It will swap the elements a[Y] and a[Z].

Input

Input starts with an integer T (≤ 100),denoting the number of test cases.

Each case contains two integers n (1 ≤ n ≤100) and m (0 ≤ m ≤ 101). The next line contains nspace separated integers denoting the elements of the array. Each of the next mlines contains an operation defined above. You can assume that no operationwill overflow/underflow the 32 bit signed integer range or access any invalidarray reference.

Output

For each case, print the case number first. In the next lineyou have to print the elements of the array. Two elements should be separatedby a single space. There should be no trailing space after the last integer ofthe array.

Sample Input

Output for Sample Input

2

5 3

1 2 3 4 5

P 0 1

S 1

R

4 2

2 7 8 1

M 10

D 5

Case 1:

6 5 4 2 3

Case 2:

4 14 16 2

 

题意

(网上都没写)

给定一个罗旅洲数组和一些操作上的数组,你必须打印数组的最后状态。说,数组是[ ],大小为n,索引从0到n-1。

操作是:

1。”S D。D是一个整数。d将添加数组中的所有元素。

2。”M D。D是一个整数。数组的所有元素将乘以D。

3。”D K。k是一个非零的整数。数组的所有元素将被K整除。

4。”R。这意味着逆转。它将反转数组的元素。

5。”P Y Z。Y和Z是整数。它将交换的元素A [ Y ]和一个[ Z ]。

代码

#include
#include
#include
#include
using namespace std;
int a[201];
char t;
int main(){
    int i,j,k,m,n,tmp,T,x,y;
    scanf("%d",&T);
    for(int c=1;c<=T;c++){
    scanf("%d%d",&n,&m);
	
    for(i=0;i





你可能感兴趣的:(1133 - Array Simulation (工业题))