水题~~

今天ac了一道acdream上的水题,来缓解一下自己的压力~~好水的题,要注意输入的格式就对了~~注意用getchar()吃掉回车:

然后就ac了~~  发现一个新的oj网站,叫 light oj,题目分类不错哦~~大家可以去水一下

http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=8954#problem/K

K - Array Simulation
Time Limit:500MS      Memory Limit:32768KB      64bit IO Format:unknown

Description

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

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

The operations are:

  1. 'S D'D is an integer. D will be added with all the elements of the array.
  2. 'M D'D is an integer. All the elements of the array will be multiplied by D.
  3. 'D K'K is a non zero integer. All the elements of the array will be divided by K (integer division).
  4. 'R'. It means reverse. It will reverse the elements of the array.
  5. 'P Y Z'Y and 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 n space separated integers denoting the elements of the array. Each of the next m lines contains an operation defined above. You can assume that no operation will overflow/underflow the 32 bit signed integer range or access any invalid array reference.

Output

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

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

Sample Output

Case 1:

6 5 4 2 3

Case 2:

4 14 16 2

 

就调用 子函数求出最终解就可以了~~~

post code:

 

#include<stdio.h>
int a[200],n,m;
char judge;

void fun1();
void fun2();
void fun3();
void fun4();
void fun5();   

int main()
{   int num=0;
    int t,i;
    scanf("%d",&t);
    while(t--)
    {   num++;

         scanf("%d %d",&n,&m);
         for(i=0;i<=n-1;i++)
           {
             scanf("%d",&a[i]);

           }
          
         for(i=1;i<=m;i++)
         {
              getchar();
              scanf("%c",&judge);
  
             switch(judge-'A')
             {
             case 18:fun1();break;
             case 12:fun2();break;
             case 3:fun3();break;
             case 17:fun4();break;
             case 15:fun5();                   
             }              
         }    
        printf("Case %d:\n",num); 
       for(i=0;i<=n-1;i++)
       {
        printf("%d",a[i]);if(i!=n-1)printf(" ");  
       }printf("\n");
         
    }
}


void fun1()
{
     int i,s;
     scanf("%d",&s);
     for(i=0;i<=n-1;i++)
     {
      a[i]+=s;                 
     }

}
void fun2()
{
   int i,d;
   scanf("%d",&d);
   for(i=0;i<=n-1;i++)
   {
     a[i]*=d;
   }  

}
void fun3()
{
     int i,k;
     scanf("%d",&k);
     for(i=0;i<=n-1;i++)
     {
     a[i]/=k;                 
     }

}

void fun4()
{    int i,temp;
     for(i=0;i<=(n-1)/2;i++)
     {
     temp=a[i];
     a[i]=a[n-i-1];   
     a[n-i-1]=temp;                    
     }
        
}
void fun5()
{  int i;
   int temp,y,z;
   scanf("%d %d",&y,&z);
   temp=a[y];
   a[y]=a[z];
   a[z]=temp;     

}

 

转载于:https://www.cnblogs.com/ysh-blog/archive/2012/07/07/2580769.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值