输入中的测试数据不超过100组。每组数据都有如下的形式,而且各组测试数据之间没有空白的行。 一组测试数据包括三部分: 1. 起始行 - 一行,包括字符串 "START" 2. 密文 - 一行,给出密文,密文不为空,而且其中的字符数不超过200 3. 结束行 - 一行,包括字符串 "END" 在最后一组测试数据之后有一行,包括字符串 "ENDOFINPUT"。
对每组数据,都有一行输出,给出密文对应的明文。
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
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
a = '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'.split() b = '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'.split() table = dict(zip(a, b)) try: while 1: s = raw_input() if s == 'ENDOFINPUT': break if s == 'START' or s == 'END': continue output = '' for i in s: if i in table: output += table[i] else: output += i print output except: pass
#include<iostream> #include<string> #include<cstring> using namespace std; int main(){ string start; while(getline(cin,start)){ if(start=="ENDOFINPUT") break; if(start=="START"){ char ch[200]; string str; getline(cin,str); strcpy(ch,str.c_str()); for(int i=0;i<str.length();i++){ if('A'<=ch[i]&&ch[i]<='Z'){ switch(ch[i]){ case 'A': ch[i]='V'; break; case 'B': ch[i]='W'; break; case 'C': ch[i]='X'; break; case 'D': ch[i]='Y'; break; case 'E': ch[i]='Z'; break; default: ch[i]-=5; } } } for(int i=0;i<str.length();i++) cout<<ch[i]; getline(cin,str); cout<<endl; } } }
using namespace std; #include <iostream> #include <cstring> int main(){ string mess; while(getline(cin, mess) and mess != "ENDOFINPUT"){ if(mess != "START" and mess != "END"){ for(int i(0);i<mess.size();++i){ if(mess[i] <= 'Z' and mess[i] >= 'A'){ mess[i] = (mess[i] - 5 - 'A' + 26)%26 + 'A'; } } cout<<mess<<endl; } } return 0; }
#include <stdio.h> (737)#include <string.h> #define SIZE 2001 int main() { char IN[3][SIZE]; int j,k; while(gets(IN[0])!=NULL) { if(strcmp(IN[0],"ENDOFINPUT")==0) { break; } gets(IN[1]); for(j=0;IN[1][j]!='\0';j++) { if(IN[1][j]>='A'&&IN[1][j]<='Z') { IN[1][j]=(IN[1][j]-'A'+21)%26+'A'; } } gets(IN[2]); puts(IN[1]); } return 0; }
#include<stdio.h> (737)#include<string.h> int main() { char a[20],b[100],c[20]; while(gets(a)!=NULL) { if(strcmp(a,"ENDOFINPUT")==0) break; gets(b); for(int i=0;i<strlen(b);i++) if(b[i]>='A'&&b[i]<='Z') { b[i]-=5; if(b[i]<'A') b[i]=b[i]+26; } gets(c); printf("%s\n",b); } return 0; }
while True: try: start = input() if start == 'ENDOFINPUT': break conversion = 'VWXYZABCDEFGHIJKLMNOPQRSTU' cipherText = input() input() clearText = [] for i in cipherText: if i.isupper(): clearText.append(conversion[ord(i)-ord('A')]) else: clearText.append(i) print("".join(clearText)) except Exception: break
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String input = scanner.nextLine(); if (input.equals("ENDOFINPUT")) break; if (input.equals("START")) continue; else if (input.equals("END")) continue; else { for (char c : input.toCharArray()) { if (Character.isUpperCase(c)) System.out.print((char) ('A' + (c - 'A' - 5 + 26) % 26)); else System.out.print(c); } System.out.println(); } } scanner.close(); } }
//用getline函数取得整行输入再进行操作 #include<iostream> using namespace std; #include<string> int main() { string s; while (getline(cin, s) && s != "ENDOFINPUT") { getline(cin, s); for (int i = 0;i<s.size();i++) { if (s[i] >= 'F' && s[i] <= 'Z') s[i] -= 5; else if (s[i] >= 'A' && s[i] <= 'E') s[i] += 'V' - 'A'; } cout << s << endl; getline(cin, s); } }
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<map> using namespace std; string change(string s) { string res; for (auto c : s) { if (c >= 'A'&&c <= 'Z') { if (c == 'A') res += 'V'; else if (c == 'B') res += 'W'; else if (c == 'C') res += 'X'; else if (c == 'D') res += 'Y'; else if (c == 'E') res += 'Z'; else res += c - 5; } else res += c; } return res; } int main() { string s; vector<string> res; while (getline(cin,s)) { string str; if (s == "START" || s == "END") continue; else if (s == "ENDOFINPUT") break; else { str = change(s); res.push_back(str); } } for (vector<string>::iterator it = res.begin(); it != res.end(); it++) cout << *it << endl; }
#include <stdio.h> #include <string.h> #define N 201 char Decode(char c) { if('A'<=c&&c<='Z') { return 'A'+(c-'A'-5+26)%26; } else return c; } int main() { char str[N]; char order[N]; while(gets(order)) { if(strcmp("ENDOFINPUT", order)==0) break; gets(str);//读取待处理字符串 gets(order);//读取"END" int len=strlen(str); for(int i=0; i<len; i++) { str[i]=Decode(str[i]); } puts(str); } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ string str; while(getline(cin,str)){ if(str=="ENDOFINPUT")break; if(str=="START"){ getline(cin,str); for(int i=0;i<str.length();i++){ if(str[i]>='A'&&str[i]<='Z'){ str[i]='Z'-('Z'-str[i]+5)%26; } } cout<<str<<endl; } getline(cin,str);//读去“END”结尾字符串 } return 0; }
不知道为啥不能通过,求解。#include<iostream>
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; //简单密码 int main(){ string str; while (getline(cin, str)){ //起始行 if (str == "ENDOFINPUT") { break; } //重新获得密文 getline(cin, str); for (int i = 0; i < str.length(); i++){ if (str[i] >= 'A' && str[i] <= 'Z') { str[i] = (str[i] - 'A' - 5 + 26) % 26 + 'A'; } } cout << str << endl; getline(cin, str); //结束行 } return 0; }
#include <iostream> using namespace std; struct change { int no; int to; }; int main() { change c[26]; string begin, end, str; //密文转换,相当于往前面走5个位置 for (int i = 0; i < 26; i++) { c[i].no = i; c[i].to = (i - 5); if (c[i].to < 0) { c[i].to += 26; } } //感觉这里面“START”和“END”好像没什么用,就看看读进来是不是“ENDOFINPUT” while (getline(cin, begin)) { if (begin == "ENDOFINPUT") { break; } //得到本题真正需要转换的字符串 getline(cin, str); for (int i = 0; i < str.size(); i++) { if (isalpha(str[i])) {//如果是字母,则进行密文转换 str[i] = c[(int)(str[i] - 'A')].to + 'A'; } } cout << str << endl; getline(cin, end); } return 0; }
#include <bits/stdc++.h> using namespace std; string wen[105]; int main() { string s1; int zuhao=0; while (cin >> s1 && s1 != "ENDOFINPUT") { string start,miwen, end; getline(cin, start);//上一句只是判断第一行,并不会吃掉他,所以要getline吃掉第一行的start getline(cin, miwen); // 读取密文 getline(cin, end); int len = miwen.size(); string mingwen; for (int i = 0; i < len; i++) { char temp = miwen[i]; if (temp >= 'F' && temp <= 'Z') { temp -= 5; mingwen += temp; } else if (temp >= 'A' && temp <= 'E') { temp += 21; mingwen += temp; } else { mingwen += temp; // 非字母字符直接添加到明文中 } } wen[zuhao++] = mingwen; } for (int j = 0; j <zuhao; j++) { // 使用 zuhao 控制输出的数量 cout << wen[j] << endl; } return 0; }
char start[20]; char str[200]; char end[10]; while(scanf("%s",start)!=EOF){ getchar(); if(strcmp(start,"ENDOFINPUT") == 0) break; gets(str); gets(end); for(int i=0;i(int)strlen(str);i++){ if(str[i] >= 'A' && str[i] 'Z'){ str[i] = str[i] - 5; if(str[i] 'A') str[i] = str[i] + 26; } printf("%c",str[i]); } } return 0;
}
#include <iostream> #include <cstdio> #include <string> using namespace std; int main(){ string start, text, end; while (getline(cin,start)){ string res; if(start == "ENDOFINPUT"){ break; } getline(cin,text); getline(cin,end); for(int i=0; i<text.size(); ++i){ if(text[i]>= 'A' && text[i] <= 'Z'){ if(text[i]<'F'){ res.push_back((char(text[i]-5+26))); }else{ res.push_back(char(text[i]-5)); } }else{ res.push_back(text[i]); } } cout << res << endl; } }