小小翻译家 【杭电-1048】 附题

/*
The Hardest Problem Ever
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15859    Accepted Submission(s): 7331

Problem Description
Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that no one could figure it out without knowing how it worked.
You are a sub captain of Caesar‘s army. It is your job to decipher the messages sent by Caesar and provide to your general. The code is simple. For each letter in a plaintext message, you shift it five places to the right to create the secure message (i.e., if the letter is ‘A‘, the cipher text would be ‘F‘). Since you are creating plain text out of Caesar‘s messages, you will do the opposite:
Cipher text
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Plain text
V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
Only letters are shifted in this cipher. Any non-alphabetical character should remain the same, and all alphabetical characters will be upper case.
 
Input
Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. All characters will be uppercase.
A single data set has 3 components:
Start line - A single line, "START"
Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar
End line - A single line, "END"
Following the final data set will be a single line, "ENDOFINPUT".
 
Output
For each data set, there will be exactly one line of output. This is the original message by Caesar.
 
Sample Input
START
NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX
END
START
N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ
END
START
IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ
END
ENDOFINPUT
 
Sample Output
IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES
I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME
DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE
*/
#include<stdio.h>     //本题中的误区就在于START 和END没有实际意义,只是表面上的开始和结束,
#include<string.h>    //换句话说,他们可以换成任何字符串,不影响输出结果。
int main()
{
  char a[20]={0};
  char s[200]={0};
        while(gets(a)){
         
         if(strcmp(a,"ENDOFINPUT")!=1) break;
          gets(s);
          gets(a);
          int len;
          len=strlen(s);
          for(int i=0;i<len;i++){
           if(s[i]>=‘A‘ && s[i]<=‘E‘){
            s[i]+=21;
           }
           else
           if(s[i]>=‘F‘ && s[i]<=‘Z‘){
            s[i]-=5;
           }
          }
          puts(s);
         
         
        }return 0;
}

/*

The Hardest Problem Ever

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 15859    Accepted Submission(s): 7331

Problem Description

Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that no one could figure
it out without knowing how it worked.

You are a sub captain of Caesar‘s army. It is your job to decipher the messages sent by Caesar and provide to your general. The code is simple. For each letter in a plaintext message, you shift it five places to the right to create the secure message (i.e.,
if the letter is ‘A‘, the cipher text would be ‘F‘). Since you are creating plain text out of Caesar‘s messages, you will do the opposite:

Cipher text

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Plain text

V W X Y Z A B C D E F G H I J K L M N O P Q R S T U

Only letters are shifted in this cipher. Any non-alphabetical character should remain the same, and all alphabetical characters will be upper case.

Input

Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. All characters will be uppercase.

A single data set has 3 components:

Start line - A single line, "START"

Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar

End line - A single line, "END"

Following the final data set will be a single line, "ENDOFINPUT".

Output

For each data set, there will be exactly one line of output. This is the original message by Caesar.

Sample Input

START

NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX

END

START

N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ

END

START

IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ

END

ENDOFINPUT

Sample Output

IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES

I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME

DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE

*/

#include<stdio.h>     //本题中的误区就在于START 和END没有实际意义,只是表面上的开始和结束,

#include<string.h>    //换句话说,他们可以换成任何字符串,不影响输出结果。

int main()

{

char a[20]={0};

char s[200]={0};

while(gets(a)){

if(strcmp(a,"ENDOFINPUT")!=1) break;

gets(s);

gets(a);

int len;

len=strlen(s);

for(int i=0;i<len;i++){

if(s[i]>=‘A‘ && s[i]<=‘E‘){

s[i]+=21;

}

else

if(s[i]>=‘F‘ && s[i]<=‘Z‘){

s[i]-=5;

}

}

puts(s);

}return 0;

}

小小翻译家 【杭电-1048】 附题

时间: 2024-08-03 10:48:13

小小翻译家 【杭电-1048】 附题的相关文章

The Hardest Problem Ever(杭电1048)

/*The Hardest Problem Ever Problem Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This c

杭电acm 1034题

Problem Description A number of students sit in a circle facing their teacher in the center. Each student initially has an even number of pieces of candy. When the teacher blows a whistle, each student simultaneously gives half of his or her candy to

杭电acm 1049题

一道水题..... 大意是一条1inch的虫子在一个n inch的盒子的底部,有足够的能够每一分钟往上爬u inch,但是需要休息一分钟,这期间会往下掉d inch,虫子爬到盒子口即认为结束.要求计算出给定的n,u,d虫子爬上的时间. 1 /****************************************************** 2 杭电acm 1049题 已AC 3 *****************************************************/

杭电acm 1076题

水题,一个求闰年的题目,复习一下闰年的求法.... 1,如果能被4整除但不能被100整除的是闰年 2,能被400整除的是闰年 题目大意是:给定一个开始年份T以及一个正数N,要求求出从T开始,到了哪一年刚好是第N个闰年,如果开始年份是闰年则记为第一个闰年.... 1 /*********************************** 2 杭电acm 1076题 已AC 3 *************************************/ 4 #include <iostream>

杭电 1048

The Hardest Problem Ever Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15844    Accepted Submission(s): 7321 Problem Description Julius Caesar lived in a time of danger and intrigue. The hard

杭电acm 2013题

蟠桃记 喜欢西游记的同学肯定都知道悟空偷吃蟠桃的故事,你们一定都觉得这猴子太闹腾了,其实你们是有所不知:悟空是在研究一个数学问题! 什么问题?他研究的问题是蟠桃一共有多少个! 不过,到最后,他还是没能解决这个难题,呵呵^-^ 当时的情况是这样的: 第一天悟空吃掉桃子总数一半多一个,第二天又将剩下的桃子吃掉一半多一个,以后每天吃掉前一天剩下的一半多一个,到第n天准备吃的时候只剩下一个桃子.聪明的你,请帮悟空算一下,他第一天开始吃的时候桃子一共有多少个呢? 这道题目几个月以前用循环做过,最近想重温下

hdu1867(A + B for you again) 杭电java a题真坑

点击打开链接 Problem Description Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as "asdf" and "sdfg", the result of the addition between them is

杭电acm 2018题

有一头母牛,它每年年初生一头小母牛.每头小母牛从第四个年头开始,每年年初也生一头小母牛.请编程实现在第n年的时候,共有多少头母牛? 因为前三年的小母牛到了第四年会生小牛,再加上前一年的母牛头数就是某年母牛的总数. f(1)=1; f(2)=2; f(3)=3; ......... f(n)=f(n-1)+f(n-3); #include<stdio.h> int f(int n); int main(void) { int n; while(scanf("%d",&

杭电 1262 寻找素数对 【素数】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1262 解题思路:先将题目中给出的偶数范围内的素数打表,设输入的那个偶数为n,这样找到n/2在素数表的位置k,从pn[k]到pn[2]:以及从pn[k]到pn[10000]依次判断相加是否等于n即可. 反思:注意像 10和26这样的偶数,应该输出的是 5 5:13 13:所以应该单独处理这种n/2等于一个素数的偶数 ps:这是在杭电的100题,这三个多月来,加油!!!!!fighting!!!!!!