【bzoj2145】悄悄话 乱搞

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

Source


k很小 可以暴力枚举

然后可以估价……然而你只要有强大的单词表的话只要判断有多少个单词匹配成功就行了…相信自己的英语能力可以试一下233

我找的某个std复制的233尝试去什么常用英语大全上去抠结果WA掉了 我是不是可以婊一下这些单词根本不常用啊!!

我的代码跑得好慢啊

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

const int SZ = 1000010;

const string biao[1000] = {"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",};

bool iszm(char s)
{
    return (s >= 'a' && s <= 'z') || (s >= 'A' && s <= 'Z');
}

string get_str(char s[],int l,int r)
{
    string ans;
    for(int i = l;i <= r;i ++)
    {
        char c = s[i];
        if(c >= 'A' && c <= 'Z') c += 32;
        ans += c;
    }
    return ans;
}

char change(char s,int k)
{
    char c = s;
    if(c >= 'a' && c <= 'z') c -= 'a',c = (c + k) % 26 + 'a';
    else  c -= 'A',c = (c + k) % 26 + 'A';
    return c;
}

char s[SZ];
char ans[30][SZ];

int get(int k)
{
    int n = strlen(s);
    memcpy(ans[k],s,sizeof(ans[k]));
    for(int i = 0;i < n;i ++)
    {
        if(iszm(s[i])) ans[k][i] = change(s[i],k);
        else ans[k][i] = s[i];
    }
    int tot = 0;
    for(int l = 0,r = 0;l < n;l = r + 2,r = l)
    {
        while(r <= n && iszm(ans[k][r])) r ++;
        r --;
        string s = get_str(ans[k],l,r);
    //  cout<<<<endl;
        for(int j = 0;biao[j] != "";j ++)
            if(s == biao[j])
            {
                tot ++;
                break;
            }
    }
    return tot;
}

int main()
{
    while(gets(s))
    {
        int maxlen = 0,pos = 0;
        for(int i = 0;i <= 25;i ++)
        {
            int maxt = get(i);
        //  printf("%d %d\n",i,maxt);
            if(maxt > maxlen)
                maxlen = maxt,pos = i;
        }
        puts(ans[pos]);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值