今天ac了一道acdream上的水题,来缓解一下自己的压力~~好水的题,要注意输入的格式就对了~~注意用getchar()吃掉回车:
然后就ac了~~ 发现一个新的oj网站,叫 light oj,题目分类不错哦~~大家可以去水一下
http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=8954#problem/K
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:
- 'S D'. D is an integer. D will be added with all the elements of the array.
- 'M D'. D is an integer. All the elements of the array will be multiplied by D.
- 'D K'. K is a non zero integer. All the elements of the array will be divided by K (integer division).
- 'R'. It means reverse. It will reverse the elements of the array.
- '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; }