帮忙解决c++问题!!

来源:百度知道 编辑:UC知道 时间:2024/06/02 03:50:09
Problem Statement for TwoRotationCypher
Problem Statement

You have decided to create your own simple encryption method for strings containing only lowercase letters and spaces. You start by splitting the alphabet into two groups. The first group consists of the first firstSize letters of the alphabet, and the second consists of the remaining 26 - firstSize letters. To encrypt a character in your message, you do the following:

1. If it a space, it is kept as is.
2. If it is a letter in the first group, it is moved firstRotate letters forward in the group, wrapping back to the start if necessary. For example, if firstSize is 6 and firstRotate is 2, then 'A' would become 'C', and 'F' would become 'B'.
3. If it is a letter in the second group, then it is moved secondRotate letters forward in the group, again wrapping back to the start of the group if necessary.

Given firstSize, firstRotate, secondRotate and a m

按照题目要求,给出加密部分代码,及测试输出的代码。

测试输出结果见代码后面,解密部分题目没有要求,我完善之后会贴到我的空间。

p.s.
四楼anon_的翻译太蹩脚了……不会是拿词霸贴的吧?
五楼nekitarc的类我测试了下,结果是对的,思路不清晰,式子看着头疼……而且没有对参数进行取值区间进行限制

完整代码:

#include <string>
#include <iostream>

using namespace std;

class TwoRotationCypher {
public:
static string encrypt(int firstSize, int firstRotate, int secondRotate, string message);
};

string TwoRotationCypher::encrypt(int firstSize, int firstRotate, int secondRotate, string message)
{
firstSize %= 26;
firstRotate %= firstSize;
secondRotate %= 25 - firstSize + 1;

string result = message;
int len = message.length();
/*
for( int j=0; j<len; j++ )
result.at(i) = tolower( result.at(i) );
*/

for( int i=0; i<len; i++ )
{
int c = message.at( i );
if( c >= 'a' && c <= 'z' ) // is lower-case a