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 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<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 using namespace std;
 5 char sh[1100],s[1100];
 6 char c;
 7 int i,j,k,l,m,n;
 8 void ac(char sh[])
 9 {
10     l=strlen(sh);
11     for(i=0;i<l;i++)
12     if(sh[i]>=‘a‘&&sh[i]<=‘z‘)
13     sh[i]-=32;//先变成大写
14     for(i=0;i<l;i++)
15     s[i]=sh[i];
16     int flag=25;
17     for(i=25;i>=0;i--)//得到密码字符串
18     {
19         for(j=0;j<l;j++)
20         if(‘Z‘-i==sh[j])
21         break;
22         if(j==l)
23         s[flag--]=‘Z‘-i;
24     }
25 }
26 int main()
27 {
28     scanf("%s",sh);
29     getchar();
30     ac(sh);
31     while(scanf("%c",&c)!=EOF)//逐个字母输入
32     {
33         for(i=0;i<26;i++)
34         {
35             if(c==s[i])
36             {
37                 printf("%c",‘A‘+i);
38                 break;
39             }
40
41             if(c==s[i]+32)
42             {
43                 printf("%c",‘a‘+i);
44                 break;
45             }
46         }
47             if(i==26)
48             printf("%c",c);
49     }
50 }
时间: 2024-10-15 15:55:45

HDU 1591 Encoded Love-letter(简单字符串)的相关文章

hdu 4763 Theme Section (简单KMP)

Theme Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1184    Accepted Submission(s): 621 Problem Description It's time for music! A lot of popular musicians are invited to join us in t

hdu 4119 Isabella&#39;s Message 【字符串处理】

Isabella's Message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2098    Accepted Submission(s): 614 Problem Description Isabella and Steve are very good friends, and they often write letters

HDU 2594 Simpsons’ Hidden Talents (字符串-KMP)

Simpsons' Hidden Talents Problem Description Homer: Marge, I just figured out a way to discover some of the talents we weren't aware we had. Marge: Yeah, what is it? Homer: Take me for example. I want to find out if I have a talent in politics, OK? M

C 封装一个通用链表 和 一个简单字符串开发库

引言 这里需要分享的是一个 简单字符串库和 链表的基库,代码也许用到特定技巧.有时候回想一下, 如果我读书的时候有人告诉我这些关于C开发的积淀, 那么会走的多直啊.刚参加工作的时候做桌面开发, 服务是C++写,界面是C#写.那时候刚进去评级我是中级,因为他问我关于系统锁和信号量都答出来.开发一段 时间,写C#也写的很溜.后面招我那个人让我转行就写C++和php,那时候就开始学习C++有关知识. 后面去四川工作了,开发安卓,用eclipse + java语法 + android jdk,开发前端,

POJ3617 简单字符串

三分之一的通过率的字符串 题意为,输入一个S串,有一个空串T.对S串有两种操作,一是取出S串的头放入T串的尾,二是取出S串的尾放入T串的尾.要求是要使得T串的字典序最小. 从题意来看是一个很明显的贪心思路.那么想到这一步其实比较接近答案了,但是需要注意的一点是当S串的头和尾相同的时候,那么这个时候我们当然也希望取出更小的字符,所以就需要比较下一个字符.但是如果指向头和尾的指针都分别往里前进一位的时候,这俩字符还是相同,咋办?这个情形...对,就是回文字符串.形同“ABCDCBA”这样的字符串.这

hdu 4119 Isabella&#39;s Message【字符串模拟】

题目链接:http://write.blog.csdn.net/postedit 自我感觉比较麻烦 #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<string> #include<map> using namespace std; const int maxh=100+10; const int maxe=100

HDU 1846 Brave Game (简单博弈)

HDU 1846 Brave Game (简单博弈) ACM 题目地址: HDU 1846 Brave Game 题意: 中文. 分析: 博弈入门. 如果n=m+1,因为最多取m个,所以先拿的人拿多少个,后拿的人能全拿走. 所以判断n%(m+1)即可. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: 1846.cpp * Create Date: 2014-09-20 10:05:26 * Descripton: game */ #

hdu 1016 Prime Ring Problem (简单DFS)

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25700    Accepted Submission(s): 11453 Problem Description A ring is compose of n circles as shown in diagram. Put natural numb

HDU 11488 Hyper Prefix Sets (字符串-Trie树)

H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of strings in the set. For example the prefix goodness of the set {000,001,0011} is 6.You are given a set of binary strings. Find the maximum prefix goodnes