zoukankan      html  css  js  c++  java
  • SDUT 2222 And Now, a Remainder from Our Sponsor(规律)

    And Now, a Remainder from Our Sponsor

    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 350    Accepted Submission(s): 144

    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

    Source

    2007 East Central North America

    解题报告:这道题就是规律题,题意就是给我们4个数之后,再给出若干个七位或八位的数,先把这个数分成四个两位的数,再找到一个数能取模后的余数正好等于分成的四个数,这个数就是所求的目标数,再根据规则变换即可!注意如最后有空格的话,不输出!

    代码如下:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    int a[5], b[5], c[5];
    int main()
    {
    int t, n, i, j, p, q;
    scanf("%d", &t);
    while (t --)
    {
    scanf("%d", &n);
    for (i = 1; i <= 4; ++i)
    {
    scanf("%d", &a[i]);
    }
    for (i = 1; i <= n; ++i)
    {
    scanf("%d", &p);
    for (j = 4; j >= 0; --j)//把所给的七位或八位数分割成四个两位数
    {
    b[j] = p % 100;
    p = p /100;
    }
    int len = 272727/a[1];
    for (j = 1; j <= len; ++j)//找到一个数能取模后等于分割后的四个数
    {
    q = j * a[1] + b[1];
    if (q % a[2] == b[2] && q % a[3] == b[3] && q % a[4] == b[4])
    {
    break;
    }
    }
    for (j = 3; j >= 0 ;--j)//把这个六位数分成三个两位的数
    {
    c[j] = q % 100;
    q = q / 100;
    }
    for (j = 1; j <= 3; ++j)
    {
    if (c[j] == 27 && i != n)//若最后有空格,不输出
    {
    printf(" ");
    }
    else if (c[j] >= 1 && c[j] <= 26)
    {
    printf("%c", c[j] + 'A' - 1);
    }
    }
    }
    printf("\n");
    }
    return 0;
    }



  • 相关阅读:
    求所有科目都大于80分的学生姓名
    sql server如何设置密码过期时间呢?
    sql server官网使用查找技术文档(msdn、联机丛书)
    【版本特性】sql server2014版本特性
    SQLSERVER文件组误脱机后如何联机
    sql server2014中的内存优化表/内存表(续写)
    JNI日志调试LOG和中文乱码
    JNI常见错误整理
    什么是“软解码”,什么又是“硬解码”呢?
    创建eclipse针对NDK的联合编译环境。
  • 原文地址:https://www.cnblogs.com/lidaojian/p/2404944.html
Copyright © 2011-2022 走看看