• Encoded Love-letter


    Encoded Love-letter

    Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 35   Accepted Submission(s) : 14
    Problem Description
    After Gardon had got Angel's letter, he found it was encoded...Oh my god, why did she encode a love-letter?? But don't worry, she wrote the algorithm for encoding after the letter: Each charactor are changed to a corresponding charactor. If the keyword is "Angel", the rule will be: ABCDEFGHIJKLMNOPQRSTUVWXYZ ANGELZYXWVUTSRQPOMKJIHFDCB You may find that in the bottom line, charactors of the keyword come first. All other charactors will come in a reversed order. Now given another keyword, work the letter out! Can you write a program to translate the letter?
     
    Input
    The letter will begin with the keyword (All uppercase), then lines of text.
     
    Output
    Decode the letter and print it out. Please note that a upper-case charactor will be decoded to a upper-case charactor, while a lower-case charactor will be decoded to a lower-case charactor.
     
    Sample Input
    ANGEL Fxlr jxaj eac W xlam cqim hqwgl W xahl kqsl kplgwat zlltwry Tlj sl atfack jxwru W eqr'j farra zqmylj cqi W mlslsnlm aj jxl eac Cqi aml atfack qr sc swre Lhlrjxqiyx W vikj gar jxwru anqij cqi Wz jxl eac wr jxl zijiml Jxwk tqhl fwtt nlgqswry jmil W'hl rlhlm gxaryl sc swre jxaj W fwtt tqhl cqi zqmlhlm W eqr'j gaml xqf zqqt wj wk W fwtt tlj sc emlas gqsl jmil W fwtt jltt cqi kqsljxwry W farra tlj cqi urqf, W tlj cqi urqf W tqhl cqi, tqhwry cqi, ak jxl sqikl tqhlk jxl mwgl Lhlr lhlmc eac xak kjqms, W fwtt atfack nc cqim kwel W swkk cqi, swkkwry cqi W eqr'j gaml xqf xame wj wk W vikj farj cqi jq nl xappc Lhlmcjxwry, W eq wj zqm cqi
     
    Sample Output
    When that day I hear your voice I have some special feeling Let me always think I don't wanna forget you I remember at the day You are always on my mind Eventhough I just can think about you If the day in the future This love will becoming true I've never change my mind that I will love you forever I don't care how fool it is I will let my dream come true I will tell you something I wanna let you know, I let you know I love you, loving you, as the mouse loves the rice Even every day has storm, I will always by your side I miss you, missing you I don't care how hard it is I just want you to be happy Everything, I do it for you
     
    Author
    DYGG
     
    Source
    HDU “Valentines Day” Open Programming Contest 2007-02-14
     
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <string.h>
     4 char c[10000000];
     5 int main()
     6 {
     7     int n,i,sign1,sign2,j,k;
     8     char a[100],b[1000];
     9     gets(a);
    10     sign1=strlen(a);
    11     for(i=0;i<26;i++)
    12      {
    13             b[i]='A'+i;
    14             b[i+26]='a'+i;
    15      }
    16     for(i=0;i<sign1;i++)
    17     {
    18         a[i+26]=a[i]+32;
    19     }
    20     for(i=sign1,j=0;i<26;i++,j++)
    21     {
    22         a[i]='Z'-j;
    23         a[i+26]='z'-j;
    24         for(k=0;k<sign1;k++)
    25         if(a[i]==a[k])
    26         {
    27             i--;break;
    28         }
    29     }
    30     while(gets(c))
    31     {
    32         sign2=strlen(c);
    33         for(i=0;i<sign2;i++)
    34         {
    35             if(c[i]>='A'&&c[i]<='Z')
    36             for(k=0;k<26;k++)
    37             if(c[i]==a[k])
    38             {
    39                 c[i]=b[k];break;
    40             }
    41             if(c[i]>='a'&&c[i]<='z')
    42             for(k=26;k<52;k++)
    43             if(c[i]==a[k])
    44             {
    45                 c[i]=b[k];break;
    46             }
    47         }
    48        printf("%s
    ",c);
    49     }
    50     return;
    51 }
    View Code
    转载请备注:
    **************************************
    * 作者: Wurq
    * 博客: https://www.cnblogs.com/Wurq/
    * Gitee: https://gitee.com/wurq
    **************************************
  • 相关阅读:
    Mysql中limit的用法详解
    EXCEPTION与ERROR的区别
    调用sed命令的三种方式
    学编程一定要上大学?美国一半码农都没有计算机学位
    awk 循环语句例子
    Ubuntu 16.04 LTS今日发布
    Ubuntu启动eclipse问题
    Vim技能修炼教程(6)
    Vim技能修炼教程(7)
    Vim技能修炼教程(5)
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750245.html
Copyright © 2020-2023  润新知