poj2041

简单题

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<algorithm>
using namespace std;

#define maxn 30

char order[maxn];
char st[maxn];
int l;

void work(char ch)
{
char x;
int d;
switch (ch)
{
case 'J':
x
= st[l - 1];
for (int i = l - 1; i > 0; i--)
st[i]
= st[i - 1];
st[
0] = x;
break;
case 'C':
x
= st[0];
for (int i = 0; i < l - 1; i++)
st[i]
= st[i + 1];
st[l
- 1] = x;
break;
case 'E':
d
= l / 2 + (l & 1);
for (int i = 0; i < l / 2; i++)
swap(st[i], st[i
+ d]);
break;
case 'A':
reverse(st, st
+ l);
break;
case 'P':
for (int i = 0; i < l; i++)
if (st[i] <= '9' && st[i] >= '0')
st[i]
= (st[i] - '0' + 9) % 10 + '0';
break;
case 'M':
for (int i = 0; i < l; i++)
if (st[i] <= '9' && st[i] >= '0')
st[i]
= (st[i] - '0' + 1) % 10 + '0';
break;
}
}

int main()
{
//freopen("t.txt", "r", stdin);
int t;
scanf(
"%d", &t);
while (t--)
{
scanf(
"%s", order);
scanf(
"%s", st);
l
= strlen(st);
for (int i = strlen(order) - 1; i >= 0; i--)
work(order[i]);
printf(
"%s\n", st);
}
return 0;
}
posted @ 2011-07-23 09:41  金海峰  阅读(166)  评论(0编辑  收藏  举报