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 }
时间: 05-03

HYSBZ 2145 悄悄话的相关文章

Xor HYSBZ - 2115 (线性基)

Xor HYSBZ - 2115 题意:给一个树,求1到n的最长路径.这里的路径定义为异或和. 线性基~~ 1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 struct LiBase{ 5 ll a[63]; 6 //初始化 7 void init(){ 8 memset(a,0,sizeof(a)); 9 } 10 //插入 11 bool insert_(ll x){ 12 for(int

HYSBZ - 1799 self 同类分布

self 同类分布 HYSBZ - 1799 给出a,b,求出[a,b]中各位数字之和能整除原数的数的个数.Sample Input 10 19 Sample Output 3 Hint [约束条件]1 ≤ a ≤ b ≤ 10^18 约束:一个数是它自己数位和的倍数,直接dp根本找不到状态,枚举数位和,因为总就162,然后问题就变成了一个数%mod=0,mod是枚举的,想想状态:dp[pos][sum][val],当前pos位上数位和是sum,val就是在算这个数%mod,(从高位算  *10

Snap们崛起告诉我们:这个世界太需要悄悄话

北京时间3月3日凌晨,"阅后即焚"应用Snapchat母公司Snap在纽约证券交易所上市.开盘价24美元,比其初定的17美元IPO价格高出近41.2%,按照24美元的股价计算,Snap的市值已经超过了336亿美元(约合2313.9亿人民币).火爆的态势,也在佐证着人们对互联网社交的深入思考. 长久以来,互联网似乎都是建立在社交元素之上的,网民在这张社交大网上不可避免的会遭遇到隐私泄露等问题.而以Snapchat为代表的"阅后即焚"反社交应用的出现及火爆,却在引领一股

HYSBZ 1036 树的统计Count(树链剖分)

HYSBZ 1036 树的统计Count 题目链接 就树链剖分,线段树维护sum和maxx即可 代码: #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; const int N = 30005; int dep[N], fa[N], son[N], sz[N], top[N], id[N], idx, val[N];

HYSBZ 1406 密码箱

1406: [AHOI2007]密码箱 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 670  Solved: 376 [Submit][Status] Description 在一次偶然的情况下,小可可得到了一个密码箱,听说里面藏着一份古代流传下来的藏宝图,只要能破解密码就能打开箱子,而箱子背面刻着的古代图标,就是对密码的提示.经过艰苦的破译,小可可发现,这些图标表示一个数以及这个数与密码的关系.假设这个数是n,密码为x,那么可以得到如下表述:

HYSBZ 2038 莫队算法

小Z的袜子(hose) Time Limit:20000MS     Memory Limit:265216KB     64bit IO Format:%lld & %llu Submit Status Practice HYSBZ 2038 Appoint description:  System Crawler  (2016-07-13) Description 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程

HDU - 2145 zz&#39;s Mysterious Present (最短路)

题目大意:有一个人,办了一个party,先到的有礼物.如果有多个人同时到达,就去家离得最远的那个,如果还是多个人同时到达,就去那个编号最大的 解题思路:最短路水题... #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> using namespace std; #define N 310 #define INF 0

HYSBZ 2243 染色 (树链剖分)

HYSBZ 2243 染色 题目链接 树链剖分,关键在于线段树的维护,对于每个结点要记录下最左边和最右边的颜色,合并的时候,如果颜色相同那么颜色段要减1 代码: #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; const int N = 100005; int dep[N], fa[N], son[N], sz[N

HYSBZ 2243

//Accepted 18440 KB 5556 ms /* source:HYSBZ 2243 time :2015.5.29 by :songt */ /*题解: 树链剖分 */ #include <cstdio> #include <cstring> const int imax_n = 100005; struct Edge { int u,v; Edge(){} Edge(int u,int v):u(u),v(v){} }edge[2*imax_n]; int head