知识点
相关文章
更多最近更新
更多hdu---1591Encoded Love-letter
2019-03-02 23:42|来源: 网路
Encoded Love-letter
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1231 Accepted Submission(s): 439
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?
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
//水题一枚,贴这个题主要是学习一下字符串的读入方式; 以及当段落之间输入有空行时,怎么处理。
// 这里是用的 判断 strlen(str) 是否为 0 来进行的判断。
// 读入含有空格的字符串这里使用的是 gets(str);
代码:
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #define N 30 char f[N]={"1ABCDEFGHIJKLMNOPQRSTUVWXYZ "},f1[N]; char str[N]; int ff[N]; char s[1000]; int main() { int i,j,k=0; freopen("in.txt","r",stdin); scanf("%s",str);getchar(); //for(i=0;i<N;i++) ff[i]=0; int len=strlen(str); for(i=1;i<=len;i++){ f1[i]=str[i-1]; ff[str[i-1]-'A'+1]=1; } j=i; for(i=26;i>=1;i--) if(ff[i]==0) f1[j++]='A'-1+i; char x=' '; //得到转换的字符数组。 while(gets(s)){ len=strlen(s); if(len==0) printf("\n"); else{ for(i=0;i<len;i++){ for(j=1;j<=26;j++) if(s[i]==f1[j] || s[i]==f1[j]-'A'+'a') break; if(j==27) printf("%c",s[i]); else if(s[i]>='a' && s[i]<='z') printf("%c",f[j]-'A'+'a'); else printf("%c",f[j]); } printf("\n"); } } return 0; }
转自:http://www.cnblogs.com/songacm/p/3537140
相关问答
更多-
be my big love什么意思[2023-12-29]
做我的爱人。 -
"When love takes over"的歌词谁有[2022-06-30]
when love takes over you 歌手:donna summer 专辑:another place and time You seem to be in a dizzy spin And you can't work it out You can't explain the mood you're in You're stumbling about But it's the same thing happening to you As happened to me I understand ... -
love怎么读语音[2022-08-24]
英文原文: love 英式音标: [lʌv] 美式音标: [lʌv] -
miss you love me 什么意思[2023-10-15]
这句句子其实是两个概念,miss you和love me,意思是“想念你、爱我” -
Love2d:站在侦测上(Love2d: stand on Detection)[2023-07-30]
这完全取决于您进行碰撞检测的方式。 “站立”是您必须在碰撞检测代码中涵盖的两个对象之间的非常确定的关系。 因此,您可能希望选择碰撞检测解决方案并针对该特定库。 This completly depends on the way you do your collision detection. "Stand on" is a very certain relation between two objects that you have to cover in your collision detection ... -
函数cross(a,b,c)是找到以下矩阵的行列式, | a.x a.y 1 | | b.x b.x 1 | = 2 * A | c.x c.y 1 | 其中A是三角形a,b,c的有符号区域。 行列式的符号也告诉我们3个点是顺时针方向还是顺时针方向。 看到这里的解释 我们这样重写一下, triA ← cross(pp[p+1],qq[q+1],pp[p]) triB ← cross(pp[p+1],qq[q],pp[p]) // This is equivalent to, // just to m ...
-
Lua / LOVE索引问题(Lua/LOVE indexing problems)[2022-02-17]
这是一个错误: arraySearch = 0 while arraySearch <= arrayLength do arraySearch = arraySearch + 1 你遍历循环arrayLength+1次,经过索引1..arrayLength+1 。 您希望仅使用索引1..arrayLength循环arrayLength次数。 解决方案是将条件更改为arraySearch < arrayLength 。 另一种(更多Lua-ly方式)是将其写成: for arraySearch = ... -
进入项目属性,Build选项卡和“Suppress warnings”文本框,输入1591。 请参阅此博客文章 ,了解更多详细信息(以及屏幕截图,尽管来自VS2005)。 Go into the project properties, the Build tab and in the "Suppress warnings" text box, enter 1591. See this blog post for more details (and a screenshot, albeit from VS20 ...
-
有两种选择。 如果你想分发你正在构建的任何东西,你几乎肯定不希望用户安装Lua,luarocks等等 - 所以最好的方法是简单地将任何库放入你的游戏/程序/ ...的文件夹中(如果一个库包含已编译的东西,你需要构建每个平台/操作系统,然后你实际上需要一个构建过程来吐出各种变体,但如果它是全部的Lua,则没有特定于平台的东西,所以只需复制它。) 另一种选择(主要用于你只需要它在你的机器上工作)是调整package.path然后love会发现事情就好了。 如果您在计算机上使用LUA_INIT / LUA_PAT ...
-
Love2d光标位置(Love2d cursor positions)[2023-05-19]
你正在克服这个问题。 你真正想要做的是在二维中定义最小值和最大值 ,监听鼠标事件,然后检查鼠标位置是否在你的边界内。 不需要遍历整个范围。 考虑一下这个例子中的'游戏',我们绘制一个简单的红色框,当点击它时切换左上角的文本显示。 local box_dims = { { 660, 770 }, { 99.33, 169.66 } } local show = false function love.mousepressed (x, y) if x >= box_d ...