ZOJ-1737 Unreliable Message
来源:互联网 发布:淘宝网天天特价在哪里 编辑:程序博客网 时间:2024/05/19 02:22
Unreliable Message
Time Limit: 2 Seconds MemoryLimit: 65536 KB
TheKing of a little Kingdom on a little island in the Pacific Ocean frequently haschildish ideas. One day he said, "You shall make use of a message relayinggame when you inform me of something." In response to the King'sstatement, 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 nextmessenger until the message got to the King.
Messages addressedto 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'sexpectations, he always received wrong messages, because each messenger changedmessages a bit before passing them to the next messenger. Since it irritatedthe King, he told you who are the Minister of the Science and Technology Agencyof the Kingdom, "We don't want such a wrong message any more. You shalldevelop software to correct it!" In response to the King's new statement,you analyzed the messengers' mistakes with all technologies in the Kingdom, andacquired the following features of mistakes of each messenger. A surprisingpoint was that each messenger made the same mistake whenever relaying amessage. The following facts were observed.
Mr. J rotates allcharacters of the message to the left by one. For example, he transforms"aB23d" to "B23da".
Miss C rotates allcharacters of the message to the right by one. For example, she transforms"aB23d" to "daB23".
Mr. E swaps theleft half of the message with the right half. If the message has an odd numberof characters, the middle one does not move. For example, he transforms"e3ac" to "ace3", and "aB23d" to"3d2aB".
Mr. A reverses themessage. For example, he transforms "aB23d" to "d32Ba".
Dr. P incrementsby one all the digits in the message. If a digit is '9', it becomes '0'. Thealphabet characters do not change. For example, he transforms "aB23d"to "aB34d", and "e9ac" to "e0ac".
Mr. M decrementsby one all the digits in the message. If a digit is '0', it becomes '9'. Thealphabet characters do not change. For example, he transforms "aB23d"to "aB12d", and "e0ac" to "e9ac".
The software youmust develop is to infer the original message from the final message, given theorder of the messengers. For example, if the order of the messengers isA->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 formatis 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 ofthe 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 theKing. 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. Thelength of a message is between 1 and 25 inclusive.
Output
The inferredmessages 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
TurnAGundam0isdefferentfr
————————————————————————————————————————————————————
#include <stdio.h>#include <string.h>void Jprocess(char *str, int len);void Cprocess(char *str, int len);void Eprocess(char *str, int len);void Aprocess(char *str, int len);void Pprocess(char *str, int len);void Mprocess(char *str, int len);int main(){int n, i, j, lenp, lens;char str[26], person[7];char resstr[26];scanf("%d", &n);getchar();while(n--) {gets(person);gets(str);lenp = strlen(person);lens = strlen(str);for(i = lenp-1; i >= 0; i--) {if(person[i] == 'J') {Jprocess(str, lens);}else if(person[i] == 'C') {Cprocess(str, lens);}else if(person[i] == 'E') {Eprocess(str, lens);}else if(person[i] == 'A') {Aprocess(str, lens);}else if(person[i] == 'P') {Pprocess(str, lens);} else {Mprocess(str, lens);}}printf("%s\n", str);}return 0;}void Jprocess(char *str, int len){int i;char c = str[len-1];for(i = len-1; i > 0; i--) {str[i] = str[i-1];}str[0] = c;}void Cprocess(char *str, int len){int i;char c = str[0];for(i = 0; i < len-1; i++) {str[i] = str[i+1];}str[len-1] = c;}void Eprocess(char *str, int len){int i, step;char c;int mid = len / 2;step = mid;if(len % 2 == 1) {step += 1;}for(i = 0; i < mid; i++) {c = str[i];str[i] = str[i+step];str[i+step] = c;}}void Aprocess(char *str, int len){int i, j;char c;for(i = 0, j = len-1; i < j; i++, j--) {c = str[i];str[i] = str[j];str[j] = c;}}void Pprocess(char *str, int len){int i;for(i = 0; i < len; i++) {if(str[i] >= '0' && str[i] <= '9') {if(str[i] == '0') {str[i] = '9';} else {str[i] -= 1;}}}}void Mprocess(char *str, int len){int i;for(i = 0; i < len; i++) {if(str[i] >= '0' && str[i] <= '9') {if(str[i] == '9') {str[i] = '0';} else {str[i] += 1;}}}}
- ZOJ-1737 Unreliable Message
- POJ - 2041Unreliable Message
- POJ 2041 Unreliable Message
- POJ 2041 Unreliable Message
- poj 2041 Unreliable Message 字符串处理
- zoj 2724 Windows Message Queue
- ZOJ 2724Windows Message Queue
- zoj 2724 Windows Message Queue
- zoj - 2724 - Windows Message Queue
- ZOJ 2724 Windows Message Queue
- ZOJ 2747 Windows Message Queue
- zoj 2724 windows message Queue
- ZOJ-2724-Windows Message Queue
- zoj 2724 Windows Message Queue
- ZOJ 2724 Windows Message Queue
- zoj 2724 Windows Message Queue 优先队列
- ZOJ 2724 Windows Message Queue 堆
- ZOJ Problem Set - 2724 Windows Message Queue
- android 基于apache ftp server
- android应用安全——通信安全(android https)
- c语言二叉树的实现
- uva 10003 切木棍
- List<T>方法调用线程同步问题
- ZOJ-1737 Unreliable Message
- SOA&&ERP&&SaaS
- 第五章、首次登陆与在线求助 man page
- TOP500、Green500强和Graph500强的最新世界排名,来自中国的超级计算机
- openstack架构
- 软件测试中的80/20原则
- ubuntu下中文乱码解决方案(全)
- 选择排序
- ZOJ-1208 Roll the Die!