B - Encoded Love-letter 字符串的处理

2019-03-02 23:55|来源: 网路

B - Encoded Love-letter
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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
 
 
 1 #include<cstdio>
 2 #include<string.h>
 3 using namespace std;
 4 char f[30]="1ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 5 char f1[100];
 6 int ff[100];
 7 char str[100];
 8 char s[1000];
 9 int main()
10 {
11     int i,j;
12     int len;
13     scanf("%s",str);
14    //puts(str);
15    getchar();
16     len=strlen(str);
17     memset(ff,0,sizeof(ff));
18     memset(f1,0,sizeof(f1));
19     for(i=1; i<=len; i++)
20     {
21         f1[i]=str[i-1];
22         ff[str[i-1]-'A'+1]=1;
23         //printf("%d ",ff[str[i-1]-'A'+1]);
24     }
25     j=i;
26     for(i=26; i>=1; i--)
27         if(ff[i]==0)
28         {
29              f1[j++]='A'-1+i;
30              //printf("%c ",f1[j-1]);
31         }
32     //printf("%s",f1);
33     while(gets(s))
34     {
35        len=strlen(s);
36        for(i=0;i<len;i++)
37        {
38            if(s[i]>='A'&&s[i]<='Z')
39            {
40                for(j=1;j<=26;j++)
41                   if(s[i]==f1[j]) printf("%c",f[j]);
42            }
43 
44            else if(s[i]>='a'&&s[i]<='z')
45            {
46                 for(j=1;j<=26;j++)
47                    if(s[i]-'a'+'A'==f1[j]) printf("%c",f[j]-'A'+'a');
48            }
49 
50            //else if(s[i]==0) printf("\n");
51            else printf("%c",s[i]);
52        }
53        printf("\n");
54     }
55 
56     return 0;
57 }

 


转自:http://www.cnblogs.com/angledamon/p/3888187

相关问答

更多
  • 字符串
  • 不幸的是,我不认为有一种方法可以确保您正在使用编码工作。 dasblinkenlight在评论中有一个好主意,尽管他不支持其他实例变量。 一个类的完整格式是{CLASSNAME=#IVARS} 。 但是,这可能会捕获其他结构,我将在下面进行解释。 类像这样编码的原因是它们被视为与结构由@encode 。 {表示结构的开始,后面跟着结构的名称和等号,然后是内容,最后} 。 所有类在等号后面都有#的原因是类结构中的第一个元素的类型为Class ,而这就是该类型的编码方式。 这意味着任何以Class开头的结构都会 ...
  • 这些函数被声明为 function DecodeBase64(const Input: AnsiString): TBytes; function EncodeBase64(const Input: Pointer; Size: Integer): AnsiString; 所以你需要在Unicode Delphi中将AnsiString强制转换为字符串, var S: string; begin S:= string(EncodeBase64(@VarName, 693)); .. 解码S ...
  • 考虑带有字符串的JSON对象看起来像这样 { 'member1' : 'some string with ¥' } 我不相信这是JSON的错。 您通过GET而不是POST将JSON对象传递给方法的可能性要大得多。 作为一个特定示例,如果您通过GET方法提交JSON并且未指定允许GET行为,则Microsoft MVC3框架将抛出关于它不安全的错误。 在这个答案中可以看出这个原因。 The solution in the end, was more of a hack, I added an ann ...
  • 快速和肮脏的方法是使用-stringByReplacingOccurrencesOfString:withString:用其等效字符替换编码的XML实体: NSString *fragment = ...; // get fragment from RSS feed [fragment autorelease]; // if not already autoreleased to prevent a memory leak fragment = [fragment stringByReplacingOcc ...
  • w3schools的URL编码器完全错了。 %D0%9E%D0%BA%D0%B6%D1%8D%D0%B7是完全有效的。 我也是这样做的 String encoded = URLEncoder.encode("Привет", "UTF-8"); 当我URL解码w3schools的答案如下 String decoded = URLDecoder.decode("%26%231055%3B%26%231088%3B%26%231080%3B%26%231074%3B%26%231077%3B%26%23109 ...
  • 我想我可能已经弄明白了。 分解查询字符串@#$%^&+=/,?><``";:\|][{} =@#$%^&+=/,?><``";:\|][{}到键/值对(按出现顺序): 键@#$%^ ,值无 键+ ,值/,?><``";:\|][{} 键@#$%^ ,值无 键+ ,值/,?><``";:\|][{} 基于https://stackoverflow.com/a/1746566/3108853 ,没有关于如何处理重复密钥的标准,因此看起来亚马逊只是选择忽略或覆盖(无法用这个测试用例来判断) ,因为重复键的值是相同 ...
  • 正文编码是Quoted-Printable; 标题(主题)编码是MIME“编码词”编码(base64的“B”类型)。 处理这两个问题的最佳方式是将电子邮件传递到能够处理MIME的模块,例如Email :: MIME或旧的和缓冲的MIME :: Lite 。 例如: # $message was retrieved from IMAP my $mime = Email::MIME->new($message); my $subject = $mime->header('Subject'); # automat ...
  • 你已经编码了字符串,所以只需解码它然后运行你的替换。 $html = urldecode($html); $replace = preg_replace('/\[\[signature\]\]/', 'replaced!', $html); 如果需要,您可以随后再次对其进行编码: $html = urlencode($html); 非正则表达式解决方案 如果您的查找/替换真的那么简单,那么您甚至不需要使用正则表达式。 只需做一个标准的字符串替换: $html = str_replace('[[signa ...
  • 它以小端 UTF-16输出。 每个字符两个字节,以十六进制形式写入。 7300 - > 73 00 - > 00 73 - >代码点115 ,表示s 。 如您所见,它将文本转换为小写(输入S变为s )。 It outputs in little-endian UTF-16. Two bytes per character, written in hexadecimal form. 7300 -> 73 00 -> 00 73 -> code point 115, meaning s. As you can ...