POJ 1298 The Hardest Problem Ever【字符串】
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
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
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【字符串】的更多相关文章
- poj 1298 The Hardest Problem Ever
题目链接:http://poj.org/problem?id=1298 题目大意:按照所给的顺序要求将输入的字符串进行排列. #include <iostream> #include &l ...
- 1298 The Hardest Problem Ever
题目链接:http://poj.org/problem?id=1298 思路分析:水题,字符偏移求解,注意字符串输入问题即可. 代码如下: #include <iostream> #inc ...
- The Hardest Problem Ever(字符串)
The Hardest Problem Ever Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24039 Accept ...
- (字符串 枚举)The Hardest Problem Ever hdu1048
The Hardest Problem Ever 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1048 Time Limit: 2000/1000 MS ...
- HDUOJ-------The Hardest Problem Ever
The Hardest Problem Ever Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- hdu_1048_The Hardest Problem Ever_201311052052
The Hardest Problem Ever Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- HDU1048The Hardest Problem Ever
The Hardest Problem Ever Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)
POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...
- poj 1298(水题)
The Hardest Problem Ever Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24241 Accept ...
随机推荐
- 【Matrix Factorization】林轩田机器学习技法
在NNet这个系列中讲了Matrix Factorization感觉上怪怪的,但是听完第一小节课程就明白了. 林首先介绍了机器学习里面比较困难的一种问题:categorical features 这种 ...
- Python 自学 Day1
作业二:编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 #!/usr/bin/env python import getpass def log(): uname = input ...
- day01--python基础1
# 01讲 - Windows下执行程序,必须加 PYTHON.在LINUX下,可以不指明是PYTHON.但是,执行钱许给予hello.py执行权限. - 其次,只要变成可执行程序,必须第一行事前 ...
- 调整CodeIgniter错误报告级别
修改位置:CI根目录 index.php 为开发环境与生产环境定义错误报告级别 if (defined('ENVIRONMENT')) { switch (ENVIRONMENT) { case 'd ...
- idea中maven项目放到包中的mapper的xml文件不发布的问题
今天重新一下mybatis的基础,然后一直报错,提示的是 result map 找不到com.zm.model.User对象可是看 mapper的写法没问题.找了半天才发现 是mapper没扫描到 解 ...
- ocrosoft Contest1316 - 信奥编程之路~~~~~第三关问题 D: 手机话费
http://acm.ocrosoft.com/problem.php?cid=1316&pid=3 题目描述 小明的手机每天消费1元,每消费K元就可以获赠1元,一开始小明有M元,问最多可以用 ...
- J2EE的十三个技术——JSP
简介 JSP,Java Server Page,Java服务器页面.它是在传统的网页HTML文件中插入Java程序段(Scriptlet)和JSP标记,从而形成JSP文件,后缀名为(*.jsp). ...
- HTML5_纯JS实现上传文件显示文件大小,文件信息,上传进度_不使用JS库
前台 html <input type="file" id="_netLogo" onchange="fileSelected();" ...
- poj 1062 昂贵的聘礼 (最短路径)
昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33365 Accepted: 9500 Descriptio ...
- JAVA输出最大值和最小值
public class MaxMin{ public static void main(String[] args) { int[] arr = new int[6]; Scanner input ...