Week11 Assignment-C-Required Questions 11-3

topic

Julius Caesar once used a very simple password. For each character in the plaintext, replace it with the character corresponding to the last 555 digits in its alphabet, so that the ciphertext is obtained. For example, the character'A' is replaced with'F'. The following is the correspondence between characters in ciphertext and plaintext. The ciphertext ABCDEFGHIJKLMNOPQRSTU VWXYZ\text{ABCDEFGHIJKLMNOPQRSTU VWXYZ}ABCDEFGHIJKLMNOPQRSTU VWXYZ plaintext VWXYZABCDEFGHIJKLMNOP QRSTU\text{VWTUXYZABCDEFGHIJKVWJKLMNOPQRNOPQRSTU\text{VWTUXYZABCDEFGHIJKFLMNOPKSQRNOPQRNOPQRNOPQRSTU\text{VWTUXYZABCDEFGHIJKVWJKS} What you need to pay attention to is that the letters appearing in the ciphertext are all capital letters. The ciphertext also includes non-letter characters, and there is no need to decode these characters.

Input format

One line gives the ciphertext, the ciphertext is not empty, and the number of characters does not exceed 200,200,200.

Output format

Output one line, which is the plaintext corresponding to the ciphertext. The extra spaces at the end of each line during output will not affect the correctness of the answer

Sample input

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

Sample output

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

Ideas

1. To enter a line of data, you need to use the getline() function.
2. If you don’t use the getline() function for this question, you can consider using the end-of-file character to determine whether a line has been read.

Code

#include<iostream>
#include<string>
using namespace std;
int main()
{
    
    
 char tmp;
 while(scanf("%c",&tmp)!=EOF)
 {
    
    
  if(tmp>='A'&&tmp<='Z')
  {
    
    
   char tmp2=(tmp-'A'-5+26)%26+'A';
   cout<<tmp2;
  } 
  else
   cout<<tmp; 
 }
 cout<<endl;
 return 0;
}

Guess you like

Origin blog.csdn.net/alicemh/article/details/105891744