zoukankan      html  css  js  c++  java
  • Substitution Cypher/替换加密字符串 ACM

    Substitution Cypher

    Time Limit: 1.0 Seconds   Memory Limit: 65536K    Multiple test files

        Substitution cyphers are the simplest of cyphers where the letters of one
    alphabet are substituted for the letters of another alphabet. In one form or
    another, they've been in use for over 2000 years.

    Input
        A line containing the plaintext alphabet
        A line containing the substitution alphabet
        Several lines of text
        
    Output
        A line containing the substitution alphabet
        A line containing the plaintext alphabet
        The converted lines of text
        
    Please note:
        All lines will be at most 64 characters, plus a trailing end-of-line
    character. Pass through all characters not found in the plaintext alphabet.

    Sample Input
    abcdefghijklmnopqrstuvwxyz
    zyxwvutsrqponmlkjihgfedcba
    Shar's Birthday:
    The birthday is October 6th, but the party will be Saturday,
    October 5.  It's my 24th birthday and the first one in some
    years for which I've been employed.  Plus, I have new clothes.
    So I have cause to celebrate.  More importantly, though,
    we've cleaned the house!  The address is 506-D Albert Street.
    Extra enticement for CS geeks:  there are several systems in
    the house, and the party is conveniently scheduled for 3 hours
    after the second CSC programming contest ends (not to mention,
    within easy walking distance)!

    Sample Output
    zyxwvutsrqponmlkjihgfedcba
    abcdefghijklmnopqrstuvwxyz
    Sszi'h Brigswzb:
    Tsv yrigswzb rh Oxglyvi 6gs, yfg gsv kzigb droo yv Szgfiwzb,
    Oxglyvi 5.  Ig'h nb 24gs yrigswzb zmw gsv urihg lmv rm hlnv
    bvzih uli dsrxs I'ev yvvm vnkolbvw.  Pofh, I szev mvd xolgsvh.
    Sl I szev xzfhv gl xvovyizgv.  Mliv rnkligzmgob, gslfts,
    dv'ev xovzmvw gsv slfhv!  Tsv zwwivhh rh 506-D Aoyvig Sgivvg.
    Ecgiz vmgrxvnvmg uli CS tvvph:  gsviv ziv hvevizo hbhgvnh rm
    gsv slfhv, zmw gsv kzigb rh xlmevmrvmgob hxsvwfovw uli 3 slfih
    zugvi gsv hvxlmw CSC kiltiznnrmt xlmgvhg vmwh (mlg gl nvmgrlm,
    drgsrm vzhb dzoprmt wrhgzmxv)!


    题目意思:
        第一行:密文字符串
        第二行:待加密的字符串
      第三行:<==第二行>
      第四行:<==第一行>
        后续行:待加密的文本
        
        每行最多64个字符(加上回车)
        第二行按理说应该和第一行长度相等,一一对应
        
    解题方法:
        在<待加密的文本>中, 如果在<待加密的字符串>数组中找到了该字符,则
    用<待加密的字符串>对应的<密文字符串>替换即可.


    #include <stdio.h>
    #include <string.h>
    
    int main(void)
    {
        char a[64];
        char b[64];
        char s[64];
    
        int i,j,len,len_a;
    
        gets(a);
        gets(b);
        puts(b);
        puts(a);
    
        len_a = strlen(a);
    
        while(gets(s)){
            len = strlen(s);
            for(i=0; i<len; i++){
                for(j=0; j<len_a; j++){
                    if(s[i] == a[j]){
                        printf("%c", b[j]);
                        break;
                    }
                }
                if(j == len_a){
                    printf("%c",s[i]);
                }
            }
            printf("\n");
        }
        return 0;
    }

    测试截图:


    女孩不哭 @ 2013-05-27 00:47:49 @ http://www.cnblogs.com/nbsofer

  • 相关阅读:
    MySQL DDL 在指定位置新增字段
    .NET平台常见技术框架整理汇总
    使用Linq求和方法Sum计算集合中多个元素和时应该注意的性能问题
    python时间操作
    django 利用原生sql操作数据库
    滑动验证码获取像素偏移量
    python opencv简单使用
    django通过旧数据库库生成models
    pandas 操作csv文件
    简单工厂模式(Simple Factory Pattern)
  • 原文地址:https://www.cnblogs.com/memset/p/3100862.html
Copyright © 2011-2022 走看看