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:

  1. Start line - A single line, "START"
  2. Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar
  3. 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 【题意】:

你是Caesar军队的一个分队长。你的工作是破译Caesar送来的信息并汇报给你的上级。
密码很简单,每一个字母对应着一个明文,你将明文向右五步来得到安全的信息。(比如,假如那个字母是‘A’,密文就是‘F’)当你将Caesar的信息中找出明文后,你要反过来做:
加密文本
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 
明文文本 
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 
密文中只有字母被切换了,非字母的字符应该保持不变,所有的字母都是大写的。

这个问题的输入包括一系列(非空)最多100个数据。每一个数据的格式会按照以下格式,并且在不同组数据间不会有空行分隔。所有的字符都是大写的。
一个单独的测试数据包括三个部分:
1. 开始行:单独的一行“START” 。
2. 加密的信息:单独的一行,由1~200个字符组成来自Caesar的一行信息。
3. 结束行:单独的一行“END” 。
最后一组测试数据结束会跟着单独的一行“ENDOFINPUT”。

【代码】:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
#pragma comment(linker, "/STACK:102400000,102400000")
#define Abs(x) ((x^(x >> 31))-(x>>31))
#define Swap(a,b) (a^=b,b^=a,a^=b)
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define EPS 1e-8
#define MOD 1000000007
#define max_ 10005
#define maxn 200002 using namespace std;
char a[];
int main()
{ while(gets(a))
{
if(!strcmp(a,"ENDOFINPUT")) break;
else if(!strcmp(a,"START")||!strcmp(a,"END")) continue;
for(int i=;a[i];i++)
{
if(isalpha(a[i]))
{
a[i]=((a[i]-'A')+-)%+'A';
}
}
puts(a);
}
return ;
}
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
#pragma comment(linker, "/STACK:102400000,102400000")
#define Abs(x) ((x^(x >> 31))-(x>>31))
#define Swap(a,b) (a^=b,b^=a,a^=b)
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define EPS 1e-8
#define MOD 1000000007
#define max_ 10005
#define maxn 200002 using namespace std;
char a[],b[];
int main()
{
char s[]={"VWXYZABCDEFGHIJKLMNOPQRSTU"};
while(gets(a))
{
int k=;
if(!strcmp(a,"ENDOFINPUT")) break;
if(strcmp(a,"START")!=&&strcmp(a,"END")!=)
{
for(int i=;a[i];i++)
{
if(isalpha(a[i]))
{
printf("%c",s[a[i]-'A']);
}
else
{
printf("%c",a[i]);
}
}
printf("\n");
}
}
return ;
}

常量字符数组妙用

POJ 1298 The Hardest Problem Ever【字符串】的更多相关文章

  1. poj 1298 The Hardest Problem Ever

    题目链接:http://poj.org/problem?id=1298 题目大意:按照所给的顺序要求将输入的字符串进行排列. #include <iostream> #include &l ...

  2. 1298 The Hardest Problem Ever

    题目链接:http://poj.org/problem?id=1298 思路分析:水题,字符偏移求解,注意字符串输入问题即可. 代码如下: #include <iostream> #inc ...

  3. The Hardest Problem Ever(字符串)

    The Hardest Problem Ever Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24039   Accept ...

  4. (字符串 枚举)The Hardest Problem Ever hdu1048

    The Hardest Problem Ever 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1048 Time Limit: 2000/1000 MS ...

  5. HDUOJ-------The Hardest Problem Ever

    The Hardest Problem Ever Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  6. hdu_1048_The Hardest Problem Ever_201311052052

    The Hardest Problem Ever Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  7. HDU1048The Hardest Problem Ever

    The Hardest Problem Ever Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  8. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  9. poj 1298(水题)

    The Hardest Problem Ever Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24241   Accept ...

随机推荐

  1. sublime text基本配置备份

    sublime text基本配置备份: // Settings in here override those in "Default/Preferences.sublime-settings ...

  2. thinkPHP 表单自动验证功能

    昨天晚上我们老大叫我弄表单自动验证功能,愁了半天借鉴了好多官网的知识,才出来,诶,总之分享一下我自己的成果吧! thinkphp 在Model基类为我们定义了自动验证的函数和正则表达式,我们只需要在对 ...

  3. 3dMax,Maya与FBX

    3DMax下载地址(包含安装教程与注册方法):http://www.3d66.com/popsoft_1.html 3DMax已经自带导出为fbx格式的功能,所以无需安装fbx插件 Maya下载地址( ...

  4. 通过命令行安装或卸载Tomcat服务

    一.安装Tomcat服务 1.打开命令提示符 方法1: 按住win+R,打开运行,输入cmd,打开命令提示符 方法2:在开始菜单>所有程序>附件>命令提示符 2. 通过命令进入到to ...

  5. unity射线碰撞检测+LayerMask的使用

    射线在unity中是个很方便的东西,对对象查找.多用于碰撞检测(如:子弹飞行是否击中目标).角色移动等提供了很大的帮助,在此做个总结与大家分享下 ,若有不足欢迎吐槽 好了,话补多说啦,直接进入主题: ...

  6. 用Margin还是用Padding?

    用margin还是用padding这个问题是每个学习CSS进阶时的必经之路. CSS边距属性定义元素周围的空间.通过使用单独的属性,可以对上.右.下.左的外边距进行设置.也可以使用简写的外边距属性同时 ...

  7. P4712 「生物」能量流动

    由于题面$markdown$格式,博主太懒不想一个一个改,所以题面见此:戳 Solution: 本题的贪心思路比较有意思,完全考读题... 首先,因为总的能量来源是$a[0]$,所以可以理解为总能量守 ...

  8. aFlex脚本入门

    aFlex脚本入门 来源:http://blog.51cto.com/virtualadc/599194 来源:http://blog.51cto.com/virtualadc/624219 对于A1 ...

  9. 【BZOJ 5048 塌陷的牧场】

    Time Limit: 25 Sec  Memory Limit: 256 MBSubmit: 77  Solved: 34[Submit][Status][Discuss] Description ...

  10. UOJ356 【JOI2017春季合宿】Port Facility

    暴力就是O(n^2)连边,二分图,这样只有22分. 我们考虑优化建边,我们按照左端点排序,对于一个新加进来的线段,我们向左端点距其最近的和他相交的线段连边,别的相交的我们连同色边,当一个点连了两条同色 ...