首页 > 其他分享 >杭电1048--输出输出格式控制

杭电1048--输出输出格式控制

时间:2023-02-06 21:07:07浏览次数:60  
标签:输出 -- text 1048 st will single Caesar line


The Hardest Problem Ever

​http://acm.hdu.edu.cn/showproblem.php?pid=1048​

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

思路:对应转换关系
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

代码:

# include <iostream>
# include <cstdio>
# include <algorithm>
# include <string.h>
# include <ctype.h>
using namespace std;

char st[1000000];
int main(){


int i,j,k,n,m;
char ch[30] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
while(gets(st)){

if(strcmp(st,"ENDOFINPUT")==0){
break;
}

if(strcmp(st,"START")==0||strcmp(st,"END")==0){
continue;
}

for(i=0;i<strlen(st);i++){
if(isupper(st[i])){
printf("%c",ch[(st[i]-'A'+21)%26]);
}else{
printf("%c",st[i]);
}
}
printf("\n");

}




return 0;
}


标签:输出,--,text,1048,st,will,single,Caesar,line
From: https://blog.51cto.com/u_15955675/6040491

相关文章

  • 杭电2086 A=?
    #include<iostream>#include<cstdio>usingnamespacestd;intmain(){intn,i,j;doublea[2],b[50000],k;while(cin>>n){cin>>a[0]>>a[1];for(i=0;i<n;i++){cin>>b[i];......
  • 杭电2086 A=? 与整数与浮点数是否相等
    A1=?ProblemDescription有如下方程:Ai=(Ai-1+Ai+1)/2-Ci(i=1,2,3,….n).若给出A0,An+1,和C1,C2,…..Cn.请编程计算A1=?Input输入包括多个测......
  • scanf与gets区别
    二者都是从终端读入字符串。功能为1、gets功能为读入一行,并将换行符转换为字符串结束符。2、scanf("%s",s);读入时,遇到空白字符,包括空格,制表符,换行符时均会停止输入。从功......
  • 简单选择排序
    选择排序(SelectionSort)的基本思想:对n个记录进行扫描,选择最小的记录,将其输出,接着在剩下的n-1个记录中扫描,选择最小的记录将其输出,……不断重复这个过程,直到只剩一个记录为止......
  • 杭电2084
    数塔在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的:有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?已经......
  • 生成不同随机数
    #include<cstdio>#include<cstdlib>#include<iostream>#include<ctime>usingnamespacestd;/*生成n个不同的数min代表最小值max生成的最大值*/i......
  • 冒泡排序法
    冒泡排序法的基本思想是:对待排序记录关键字从后往前(逆序)进行多遍扫描,当发现相邻两个关键字的次序与排序要求的规则不符时,就将这两个记录进行交换。这样,关键字较小......
  • 排序的分类
    ......
  • 杭电1171
    BigEventinHDUProblemDescriptionNowadays,weallknowthatComputerCollegeisthebiggestdepartmentinHDU.But,maybeyoudon’tknowthatComputerColl......
  • 矢量叉积判断顺时针还是逆时针
    利用矢量叉积判断是逆时针还是顺时针。设A(x1,y1),B(x2,y2),C(x3,y3),则三角形两边的矢量分别是:AB=(x2-x1,y2-y1),AC=(x3-x1,y3-y1)则AB和AC的叉积为:(2*2的行......