Simple password (Peking University retest on the machine)

Foreword:

21. Regardless of whether you can enter the retest or not, record the garbage code written on the road. I originally gnawed on "Algorithm Notes", but I felt too much to do it, so I changed it to the Kingway Computer Test Guide.

Title description:

Julius Caesar once used a very simple password. For each character in the plaintext, replace it with the character corresponding to the last 5 digits of its alphabet, so that the ciphertext is obtained. For example, the character A is replaced by F. The following is the correspondence between characters in ciphertext and plaintext. Ciphertext ABCDEFGHIJKLMNOPQRSTU VWXYZ plaintext VWXYZABCDEFGHIJKLMNOP QRSTU Your task is to decrypt the given ciphertext to get the plaintext. 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.

Enter description

The test data in the input does not exceed 100 groups. Each set of data has the following form, and there is no blank line between each set of test data.
A set of test data includes three parts:

  1. Start line-one line including the string "START"
  2. Cipher text-one line, giving the cipher text, the cipher text is not empty, and the number of characters in it does not exceed 200
  3. End line-one line, including the string "END"
    , there is a line after the last set of test data, including the string "ENDOFINPUT".

Output description:

For each group of data, there is a line of output, giving the plaintext corresponding to the ciphertext.

answer

#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;

int main()
{
    
    	
	string str;
	while (getline(cin,str)) {
    
    
		if (str == "START" || str == "END")
			continue;
		else
			if (str == "ENDOFINPUT")
				break;
		else{
    
    
			for (int i = 0; i < str.length(); i++)
				if (str[i] >= 'A' && str[i] <= 'Z')
					if (str[i] - 5 >= 65)
						str[i] -= 5;
					else
						str[i] = 'Z' + str[i] - 'A' - 4;
			cout << str << endl;
		}
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_44897291/article/details/112816956