zoukankan      html  css  js  c++  java
  • [解题报告]458 The Decoder

     

     The Decoder 

    Write a complete program that will correctly decode a set of characters into a valid message. Your program should read a given file of a simple coded set of characters and print the exact message that the characters contain. The code key for this simple coding is a one for one character substitution based upon a single arithmetic manipulation of the printable portion of the ASCII character set.

    Input and Output

    For example: with the input file that contains:

    1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu5
    1PIT'pz'h'{yhklthyr'vm'{ol'Pu{lyuh{pvuhs'I|zpulzz'Thjopul'Jvywvyh{pvu5
    1KLJ'pz'{ol'{yhklthyr'vm'{ol'Kpnp{hs'Lx|pwtlu{'Jvywvyh{pvu5

    your program should print the message:

    *CDC is the trademark of the Control Data Corporation.
    *IBM is a trademark of the International Business Machine Corporation.
    *DEC is the trademark of the Digital Equipment Corporation.

    Your program should accept all sets of characters that use the same encoding scheme and should print the actual message of each set of characters.

    Sample Input

    1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu5
    1PIT'pz'h'{yhklthyr'vm'{ol'Pu{lyuh{pvuhs'I|zpulzz'Thjopul'Jvywvyh{pvu5
    1KLJ'pz'{ol'{yhklthyr'vm'{ol'Kpnp{hs'Lx|pwtlu{'Jvywvyh{pvu5

    Sample Output

    *CDC is the trademark of the Control Data Corporation.
    *IBM is a trademark of the International Business Machine Corporation.
    *DEC is the trademark of the Digital Equipment Corporation.



    看完题就傻了,WTF,仔细再看了一遍才发现简单到爆

    The code key for this simple coding is a one for one character substitution based upon a single arithmetic manipulation of the printable portion of the ASCII character set.

    这个句子就是关键句,关键词:一一对应,算法规则只有一种,ASCII表

    这说明密文翻译是基于ASCII表的,而且算法只有一个

    所以一开始写了一个简单程序找到了规律

    #include<stdio.h>
    void main()
    {
        int i;
        i='1'-'*';
        printf("%d",i);
    }

    运行结果为7

    这说明密文中每一个字符所对应的ASCII值减去7就是原文中每一个字符所对应的ASCII值

    要注意如果没有赋初值就整体字符组打印,会出现乱码

    下面这个程序不知道为毛判题系统一直“- In queue -”了六分钟(。。。)然后告诉我提交错误

    #include<stdio.h>
    #include<string.h>
    void main()
    {
        int i,n;
        char miwen[100000];
        while(gets(miwen)!=EOF)
        {
            n=strlen(miwen);
            for(i=0;i<n;i++)
            {
                printf("%c",miwen[i]-7);
            }
            printf("\n");
        }
    }

    而这个就AC

    #include<stdio.h>
    #include<string.h>
    void main()
    {
        int i,n;
        char miwen[100000];
        while(gets(miwen)!=NULL)
        {
            n=strlen(miwen);
            for(i=0;i<n;i++)
            {
                printf("%c",miwen[i]-7);
            }
            printf("\n");
        }
    }

    看来得研究一下NULL和EOF的区别。。。。

  • 相关阅读:
    iis6-0 cve-2017-7269 批量验证脚本
    JSP入门基础知识详细版(通俗易懂)
    会话技术——Cookies和Session详解
    Servlet技术——request、respone详解
    Servlet技术之——概述、实现、细节、获取资源、ServletConfig、ServletContext
    我叫Tomcat:一款web服务器
    简单谈一谈Java内部类的使用原因
    XML基础知识归纳(通俗易懂)
    一个后端开发者的前端语言基础:JavaScript
    HTML5 & CSS初学者教程(详细、通俗易懂)
  • 原文地址:https://www.cnblogs.com/TheLaughingMan/p/2892077.html
Copyright © 2011-2022 走看看