这里的算法非常简单,就是“模拟”,注意编写每个传令官的算法时先分开测试,放在一起就会混淆。

POJ - 2041Unreliable Message

Time Limit: 1000MS Memory Limit: 30000KB 64bit IO Format: %I64d & %I64u

Description

The King of a little Kingdom on a little island in the Pacific Ocean frequently has childish ideas. One day he said, "You shall make use of a message relaying game when you inform me of something." In response to the King's statement, six servants were selected as messengers whose names were Mr. J, Miss C, Mr. E, Mr. A, Dr. P, and Mr. M. They had to relay a message to the next messenger until the message got to the King. Messages addressed to the King consist of digits ('0'-'9') and alphabet characters ('a'-'z', 'A'-'Z'). Capital and small letters are distinguished in messages. For example, "ke3E9Aa" is a message. Contrary to King's expectations, he always received wrong messages, because each messenger changed messages a bit before passing them to the next messenger. Since it irritated the King, he told you who are the Minister of the Science and Technology Agency of the Kingdom, "We don't want such a wrong message any more. You shall develop software to correct it!" In response to the King's new statement, you analyzed the messengers' mistakes with all technologies in the Kingdom, and acquired the following features of mistakes of each messenger. A surprising point was that each messenger made the same mistake whenever relaying a message. The following facts were observed. Mr. J rotates all characters of the message to the left by one. For example, he transforms "aB23d" to "B23da". Miss C rotates all characters of the message to the right by one. For example, she transforms "aB23d" to "daB23". Mr. E swaps the left half of the message with the right half. If the message has an odd number of characters, the middle one does not move. For example, he transforms "e3ac" to "ace3", and "aB23d" to "3d2aB". Mr. A reverses the message. For example, he transforms "aB23d" to "d32Ba". Dr. P increments by one all the digits in the message. If a digit is '9', it becomes '0'. The alphabet characters do not change. For example, he transforms "aB23d" to "aB34d", and "e9ac" to "e0ac". Mr. M decrements by one all the digits in the message. If a digit is '0', it becomes '9'. The alphabet characters do not change. For example, he transforms "aB23d" to "aB12d", and "e0ac" to "e9ac". The software you must develop is to infer the original message from the final message, given the order of the messengers. For example, if the order of the messengers is A->J->M->P and the message given to the King is "aB23d", what is the original message? According to the features of the messengers' mistakes, the sequence leading to the final message is "32Bad"->"daB23"->"aB23d"->"aB12d"->"aB23d": As a result, the original message should be "32Bad".

Input

The input format is as follows. n The order of messengers The message given to the King ... The order of messengers The message given to the King The first line of the input contains a positive integer n, which denotes the number of data sets. Each data set is a pair of the order of messengers and the message given to the King. The number of messengers relaying a message is between 1 and 6 inclusive. The same person may not appear more than once in the order of messengers. The length of a message is between 1 and 25 inclusive.

Output

The inferred messages are printed each on a separate line.

Sample Input

5

AJMP

aB23d

E

86AE

AM

6

JPEM

WaEaETC302Q

CP

rTurnAGundam1isdefferentf

Sample Output

32Bad

AE86

7

EC302QTWaEa

TurnAGundam0isdefferent

Source Japan 2003,Aizu

 #include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h> int main()
{
int n = ;
scanf("%d", &n);
char str[], order[];
for(int i = ; i < n; i++) {
scanf("%s", str);
scanf("%s", order);
int r = strlen(str);
int len = strlen(order);
char ch;
int t;
for(int i = r-; i >= ; i--) {
switch(str[i]){
printf("str -- %c\n", str[i]);
case 'J':
ch = order[len-];
for(int j = len-; j > ; j--) {
order[j] = order[j-];
}
order[] = ch;
break;
case 'C':
ch = order[];
for(int j = ; j < len-; j++) {
order[j] = order[j+];
}
order[len-] = ch;
break;
case 'E':
t = len/;
for(int i = ; i < t; i++) {
ch = order[i];
if(len%) {
order[i] = order[i+t+];
order[i+t+] = ch;
}
else {
order[i] = order[i+t];
order[i+t] = ch;
}
}
break;
case 'A':
t = len/;
for(int i = ; i < t; i++) {
ch = order[i];
order[i] = order[len--i];
order[len--i] = ch;
}
break;
case 'P':
for(int i = ; i < len; i++) {
if(order[i] >= '' && order[i] <= '') {
if(order[i] == '') order[i] = '';
else order[i]--;
}
}
break;
case 'M':
for(int i = ; i < len; i++) {
if(order[i] >= '' && order[i] <= '') {
if(order[i] == '') order[i] = '';
else order[i]++;
}
}
break;
}
}
printf("%s\n", order);
}
return ;
}

POJ - 2041Unreliable Message的更多相关文章

  1. OpenJudge / Poj 2141 Message Decowding

    1.链接地址: http://poj.org/problem?id=2141 http://bailian.openjudge.cn/practice/2141/ 2.题目: Message Deco ...

  2. Eclipse 4.2 failed to start after TEE is installed

    ---------------  VM Arguments---------------  jvm_args: -Dosgi.requiredJavaVersion=1.6 -Dhelp.lucene ...

  3. POJ 2774 Long Long Message 后缀数组

    Long Long Message   Description The little cat is majoring in physics in the capital of Byterland. A ...

  4. poj 2774 Long Long Message 后缀数组基础题

    Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 24756   Accepted: 10130 Case Time Limi ...

  5. 后缀数组(模板题) - 求最长公共子串 - poj 2774 Long Long Message

    Language: Default Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 21 ...

  6. POJ 2774 Long Long Message (Hash + 二分)

    Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 34473   Accepted: 13 ...

  7. POJ 2774 Long Long Message [ 最长公共子串 后缀数组]

    题目:http://poj.org/problem?id=2774 Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total ...

  8. POJ 题目2774 Long Long Message(后缀数组,求最长公共子串长度)

    Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 23696   Accepted: 97 ...

  9. Long Long Message POJ - 2774 后缀数组

    The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him ...

随机推荐

  1. MVC在VIEW中动态控制htmlAttributes和routevalues的方法

    在项目中有一个Html.DropDownListFor放在一个分部视图中,然后调用这个分部视图时需要动态控制这个DropDownList的显示方式,比如宽度.是否禁用.是否列表等,这些值的设置都在Ht ...

  2. 获得输入框的文本document.getElementById('id').value;

    <input id="demo" type="text" value="" > x=document.getElementByI ...

  3. Tram---poj1847(简单最短路)

    题目链接:http://poj.org/problem?id=1847 题意:给了N个交叉口,每个交叉口有自己能转到的交叉口. 注意这里:First number in the i-th line, ...

  4. Xor Sum---hdu4825(01字典树模板)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4825 题意:有n个数m个查找,每个查找有一个数x, 从序列中找到一个数y,使得x异或y最大 ...

  5. 控制台打印出event对象时,对象里面的currentTarget为null

    但是MouseEvent对象展开时 附上老外的解释~~~: http://stackoverflow.com/questions/26496176/when-loggin-an-event-objec ...

  6. Windows-005-显示隐藏文件

    此文主要讲述如何设置 Win7 系统显示隐藏的文件.文件夹和驱动器,敬请亲们参阅.若有不足之处,敬请大神指正,不胜感激!详情如下: Win7 系统安装完成后,默认是不显示隐藏的文件.文件夹和驱动器的( ...

  7. Android Annotations 注解例子

    1.AndroidAnnotations官网: http://androidannotations.org/ (也许你需要FQ) 2.eclipse中使用androidannotations的配置方法 ...

  8. offset/client/scroll一些总结

    offset/client/scroll一些总结 1.offset 首先offset共有五个值 1.offsetParent 2.offsetTop 3.offsetLeft 4.offsetWidt ...

  9. textarea 默认文字获取焦点失去焦点

    <textarea name="textarea" cols="" title="contactForm" class="t ...

  10. 什么是BI及哪些行业需要用到BI?

    什么是BI?哪些行业需要用到BI?BI——就是分析利用企业已有的各种商用数据来了解企业的经营状况和外部环境,从而为企业的经营决策提供数据支撑.下面我们来详细分解下: 企业应用BI的目标即是期望通过对来 ...