zoukankan      html  css  js  c++  java
  • HYSBZ 2145 悄悄话

    2145: 悄悄话

    Time Limit: 10 Sec  Memory Limit: 259 MB
    Submit: 271  Solved: 104
    [Submit][Status][Discuss]

    Description

    在这个有话不直说的年代,密码学越来越被广泛接受。我们引用经典的“凯撒密码”。在英文中,凯撒加密只对26个字母生效(分大小写)我们按照a到z来排字母。凯撒加密的原理就是把原文的每一个字母都按顺序往后移K位。这个K将被作为密钥。(’a’往后移变成’b’,’z’往后移会变成’a’) (0< = K< = 25)现在给出一系列用凯撒加密的英文句子,请你编写程序逐句翻译。也就是说,请你确定一个密钥,使得解码以后的文字最符合英文的规则与规范。数据保证存在唯一的解码方案,使得明码是完全可以分辨的英文句子。

    Input

    输入一定包括10行每一行都是用同一密钥加密的英文。

    Output

    输出10行,为解密结果。不允许格式上有任何不同。

    Sample Input

    Welcome to the test. This is the 1st sample test case.
    Vdkbnld sn sgd sdrs. Sghr hr sgd 2mc rzlokd sdrs bzrd.
    Welcome to the test. This is the 3rd sample test case.
    Nvctfdv kf kyv kvjk. Kyzj zj kyv 4ky jrdgcv kvjk trjv.
    Govmywo dy dro docd. Drsc sc dro 5dr ckwzvo docd mkco.
    Nvctfdv kf kyv kvjk. Kyzj zj kyv 6ky jrdgcv kvjk trjv.
    Jrypbzr gb gur grfg. Guvf vf gur 7gu fnzcyr grfg pnfr.
    Ucjamkc rm rfc rcqr. Rfgq gq rfc 8rf qyknjc rcqr ayqc.
    Ckriusk zu znk zkyz. Znoy oy znk 9zn ygsvrk zkyz igyk.
    Xfmdpnf up uif uftu. Uijt jt uif mbtu tbnqmf uftu dbtf.

    Sample Output

    Welcome to the test. This is the 1st sample test case.
    Welcome to the test. This is the 2nd sample test case.
    Welcome to the test. This is the 3rd sample test case.
    Welcome to the test. This is the 4th sample test case.
    Welcome to the test. This is the 5th sample test case.
    Welcome to the test. This is the 6th sample test case.
    Welcome to the test. This is the 7th sample test case.
    Welcome to the test. This is the 8th sample test case.
    Welcome to the test. This is the 9th sample test case.
    Welcome to the test. This is the last sample test case.
    【数据说明】
    数据将从不同的方面考察。请尽量保证程序的准确性。
    每一行长度不会太短(不少于3个单词的完整句)。没有全角字符和其他语言符号,可能包含半角空格和标点。
    单个测试点不超过5kB。

    HINT

     
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 std::string tmp,dict[700]={"a","i","am","an","as","at","be","by","do","go","he","if","in","is","it","ll","me","mr","my","no","of","on","or","re","so","to","up","ve","we","ago","all","and","any","are","bar","bat","big","bit","boy","bug","but","can","cat","cup","cut","day","did","dog","don","end","fee","fly","for","fox","fur","get","gnu","god","gpl","had","has","her","him","his","how","iee","iel","its","joy","key","law","let","may","mrs","new","nor","not","now","one","our","out","paw","pay","ran","run","sat","saw","see","set","she","six","tea","the","too","two","use","war","was","way","who","why","yet","you","zoo","adam","also","aren","away","back","bank","bear","beat","beef","been","bell","bill","bird","boar","body","bone","book","bore","both","came","camp","case","code","come","cook","copy","damn","damp","date","dead","deer","deny","dish","does","dull","each","ever","eyes","face","felt","fill","find","fire","fish","five","four","free","from","gain","gave","gets","girl","give","glad","good","hand","hard","have","here","high","hold","hour","hunt","ieee","into","jack","just","keep","kept","kiss","knew","know","lamb","last","lazy","lead","left","lend","life","like","live","long","look","love","made","make","many","mars","mary","meat","meet","mind","mine","moon","moor","more","morn","most","much","must","name","need","nine","once","only","over","paid","pain","papa","pass","past","pays","pink","play","poor","pray","puma","rain","ramp","rope","said","sake","same","seen","shed","show","sing","some","song","stop","such","sure","take","tape","tell","than","that","them","then","they","this","tied","time","tiny","told","tony","took","tree","trip","true","upon","used","user","very","wall","want","wasn","ways","well","went","were","what","when","whom","wife","wild","will","wish","with","wood","work","year","your","about","added","adore","after","again","aleko","along","among","apple","apply","armed","asked","began","being","below","betty","black","blade","bleed","blood","bored","brown","carry","catch","cause","chuck","clock","comes","could","death","doesn","doing","dwelt","eight","every","facts","fetch","field","fifty","first","forty","found","fully","given","gives","going","grant","great","hands","happy","hares","heart","hours","human","jumps","keeps","kinds","known","lamps","large","legal","lines","lived","local","lover","lovin","madam","makes","marks","merry","miles","money","moses","names","never","night","offer","often","other","paint","parts","place","plain","plays","price","prize","prove","pumas","quick","quiet","reach","right","roses","scamp","seven","shall","share","shine","sight","since","sixty","small","sorry","south","speak","stars","start","steel","steps","still","sword","table","taken","teeth","terms","thank","theft","their","there","these","thief","thing","think","those","three","times","today","torch","tower","trade","trail","truly","trust","under","users","vicar","wants","watch","weeks","where","which","while","white","whole","wings","woken","woman","words","works","world","worth","would","yards","years","yours"};
     5 char s[1000],s0[1000],s1[30];int ii=10,i,j,k,l,ans,now,key;
     6 int inmap(){
     7     for(int i=0;i<441;i++)if(tmp==dict[i])return 1;
     8     return 0;
     9 }
    10 int check(int key){
    11     int f=0;memset(s0,0,sizeof(s0));
    12     for(j=0;s[j];j++)
    13     if(s[j]>='A'&&s[j]<='Z')s0[j]=s[j]-'A'+'a';
    14     else s0[j]=s[j];
    15     for(j=0;s0[j];j++)if(s0[j]>='a'&&s0[j]<='z')s0[j]=(s0[j]-'a'+key)%26+'a';
    16     for(j=0;s0[j];j++)
    17     if(s0[j]>='a'&&s0[j]<='z'){
    18         for(tmp="",k=j,l=0;s0[k]&&s0[k]>='a'&&s0[k]<='z';k++)tmp+=s0[k];
    19         if(inmap())f++;j=k-1;
    20     }
    21     return f;
    22 }
    23 int main(){
    24     //freopen("sh.txt","r",stdin);
    25     for(int k;gets(s);puts(s)){
    26         for(ans=0,k=0;k<26;k++)if((now=check(k))>ans)ans=now,key=k;
    27         for(i=0;s[i];i++)
    28         if(s[i]>='a'&&s[i]<='z')s[i]=(s[i]-'a'+key)%26+'a';
    29         else if(s[i]>='A'&&s[i]<='Z')s[i]=(s[i]-'A'+key)%26+'A';
    30     }
    31 }
  • 相关阅读:
    写一个列表生成式,产生一个公差为11的等差数列
    如果对方网站反爬取,封IP了怎么办?
    为什么会选择redis数据库?
    你是否了解谷歌的无头浏览器?
    遇到的反爬虫策略以及解决方法?
    常见的HTTP方法有哪些?
    遇到反爬机制怎么处理?
    列举网络爬虫所用到的网络数据包,解析包?
    python中的关键字yield有什么作用?
    如下代码输出的是什么?
  • 原文地址:https://www.cnblogs.com/shenben/p/5459943.html
Copyright © 2011-2022 走看看