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

B - Encoded Love-letter

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 1591

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 }

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

时间: 2024-10-21 19:33:21

B - Encoded Love-letter 字符串的处理的相关文章

写一个程序,用于分析一个字符串中各个单词出现的频率,并将单词和它出现的频率输出显示。(单词之间用空格隔开,如“Hello World My First Unit Test”);

import java.io.BufferedReader; import java.io.FileReader; import java.io.FileNotFoundException; import java.io.IOException; import java.util.*; public class one{ public static void main(String[] args) { try { BufferedReader br = new BufferedReader(ne

jQuery九类选择器

jQuery选择器基本选择器 #id/标签名/样式名/选择器A,选择器B jQuery层次选择器 *form input:查询form下所有input元素,含有后代关系 form>input:查询form下所有input元素,有有父子关系,没有后代关系 form+input:查询与form同级的第一个input元素,是兄弟关系 form~input:查询与form同级的所有input元素,是兄弟关系 jQuery增强型基本选择器 :first:查询第一个元素 :last:查询最后个元素 :che

HDU 1591 Encoded Love-letter(简单字符串)

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1780    Accepted Submission(s): 635 Problem Description After Gardon had got Angel's letter, he found it was encoded...Oh my god, why did she enco

leetCode 17. Letter Combinations of a Phone Number 字符串 | 回溯 | Medium

17. Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string "23"Ou

poj 1171 Letter Game 字符串处理

#include <iostream> using namespace std; char s[16]; int cnt[256]; int tot[256]; int m[256]; struct DICT { char words[10]; int len,val; }dic[40010]; int tovalue(char ch[]) { int sum=0; for(int i=0;ch[i]!='\0';++i) sum+=m[ch[i]]; return sum; } int ad

swift中文文档翻译之--字符串和字符

字符串和字符 A string is an ordered collection of characters, such as "hello, world" or "albatross". Swift strings are represented by the String type, which in turn represents a collection of values of Character type. Swift's String and Char

HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)

并不是很精简,随便改改A过了就没有再简化了. 1020. Problem Description Given a string containing only 'A' - 'Z', we could encode it using the following method: 1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only c

R5&mdash;字符串处理/正则表达式

R通常被用来进行数值计算比较多,字符串处理相对较少,而且关于字符串的函数也不多,用得多的就是substr.strsplit.paste.regexpr这几个了.实际上R关于字符串处理的功能是非常强大的,因为它甚至可以直接使用Perl的正则表达式,这也是R的一个理念,作为语言就把向量计算做到极致,作为环境,就在各领域都集成最好的.R中有grep系列的函数,可以用最强大的方式处理字符串的所有问题. grep的全称是global search regular expression and print

[Swift]LeetCode880. 索引处的解码字符串 | Decoded String at Index

An encoded string S is given.  To find and write the decodedstring to a tape, the encoded string is read one character at a time and the following steps are taken: If the character read is a letter, that letter is written onto the tape. If the charac