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的区别。。。。

  • 相关阅读:
    【NOIP2012模拟10.6】填充棋盘
    【NOIP2012模拟10.6】购买
    ASP.NET网站权限设计实现(二)——角色权限绑定
    ASP.NET网站权限设计实现(一)——使用PowerDesigner进行数据库设计
    获取post发送过来的xml包
    js正则表达式30分钟入门教程
    SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
    js 取整
    [ASP.NET MVC2 系列] ASP.Net MVC教程之《在15分钟内用ASP.Net MVC创建一个电影数据库应用程序》
    c# 多线程排队队列实现的源码
  • 原文地址:https://www.cnblogs.com/TheLaughingMan/p/2892077.html
Copyright © 2011-2022 走看看