Problem Description
IBM has decided that all messages sent to and from teams competing in the ACM programming contest should be encoded. They have decided that instead of sending the letters of a message, they will transmit their remainders relative to some secret keys which are four, two-digit integers that are pairwise relatively prime. For example, consider the message "THE CAT IN THE HAT". The letters of this message are first converted into numeric equivalents, where A=01, B=02, ..., Z=26 and a blank=27. Each group of 3 letters is then combined to create a 6 digit number. (If the last group does not contain 3 letters it is padded on the right with blanks and then transformed into a 6 digit number.) For example
THE CAT IN THE HAT → 200805 270301 202709 142720 080527 080120
Each six-digit integer is then encoded by replacing it with the remainders modulo the secret keys as follows: Each remainder should be padded with leading 0’s, if necessary, to make it two digits long. After this, the remainders are concatenated together and then any leading 0’s are removed. For example, if the secret keys are 34, 81, 65, and 43, then the first integer 200805 would have remainders 1, 6, 20 and 38. Following the rules above, these combine to get the encoding 1062038. The entire sample message above would be encoded as
1062038 1043103 1473907 22794503 15135731 16114011
Input
The input consists of multiple test cases. The first line of input consists of a single positive integer n indicating the number of test cases. The next 2n lines of the input consist of the test cases. The first line of each test case contains a positive integer (< 50) giving the number of groups in the encoded message. The second line of each test case consists of the four keys followed by the encoded message.
Each message group is separated with a space.
Output
For each test case write the decoded message. You should not print any trailing blanks.
Sample Input
2
6
34 81 65 43 1062038 1043103 1473907 22794503 15135731 16114011
3
20 31 53 39 5184133 14080210 7090922
Sample Output
THE CAT IN THE HAT
THE END
http://blog.csdn.net/eeeaaaaa/article/details/37902185
问题描述
IBM已经决定,所有发送到ACM编程竞赛的团队之间的消息都应该编码。他们已经决定不再发送信息的字母,而是相对于一些秘密密钥发送剩余的信息,这些秘密密钥是四位数整数,成对的相对素数。例如,考虑到“帽子里的猫”这句话。这条消息的字母首先转换为数字等价物,其中A=01,B=02,...,Z=26,a空白=27。每组3个字母然后组合,以创建一个6位数的数字。(如果最后一个组不包含3个字母,则在右边填充空格,然后转换成一个6位数字)。
戴帽子的猫
→200805 270301 202709 142720 080527 080120
然后将每个六位数整数替换为剩余的整数,然后按如下方式调制秘密键:如果有必要,每个余数都应加上前导0,使其长2位。在此之后,剩余的连接在一起,然后任何前导0被删除。例如,如果密钥是34、81、65和43,那么第一个整数200805将有剩余数1、6、20和38。按照上面的规则,这些组合得到编码1062038。上面的整个示例消息将被编码为
1062038 1043103 1473907 22794503 15135731 16114011
输入
输入由多个测试用例组成。第一行输入由一个正整数n组成,表示测试用例的数量。输入的下一个2n行由测试用例组成。每个测试用例的第一行包含一个正整数(<50),表示编码消息中的组数。每个测试用例的第二行由四个键组成,后面跟着编码的消息。
每个消息组都用一个空格分隔。
输出量
对于每个测试用例,编写解码消息。您不应打印任何尾随空白。
样本输入
二
六
34 81 65 43 1062038 1043103 1473907 22794503 15135731 16114011
三
20 31 53 39 5184133 14080210 7090922
样本输出
戴帽子的猫
终结