Connection Status:
Competition Arena > TwoRotationCypher
SRM 378 · 2007-11-20 · by bmerry · Simulation, String Manipulation
Class Name: TwoRotationCypher
Return Type: String
Method Name: encrypt
Arg Types: (int, int, int, string)
Problem Statement

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 message, return the encrypted form of the message.

Constraints

  • firstSize will be between 1 and 25, inclusive.
  • firstRotate will be between 0 and firstSize - 1, inclusive.
  • secondRotate will be between 0 and 25 - firstSize, inclusive.
  • message will contain between 1 and 50 characters, inclusive.
  • message will contain only lowercase letters ('a' - 'z') and spaces.
Examples
0)
13
0
0
"this string will not change at all"
Returns: "this string will not change at all"
1)
13
7
0
"only the letters a to m in this string change"
Returns: "onfy tbl flttlrs h to g cn tbcs strcna jbhnal"
2)
9
0
16
"j to z will change here"
Returns: "z sn y vikk chamge heqe"
3)
17
9
5
"the quick brown fox jumped over the lazy dog"
Returns: "yqn izalc kwgsf ogt bzehnm grnw yqn djvu mgp"
4)
3
1
2
"  watch   out for strange  spacing "
Returns: "  ybvaj   qwv hqt uvtbpig  urbakpi "

Submissions are judged against all 26 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TwoRotationCypher with a public method string encrypt(int firstSize, int firstRotate, int secondRotate, string message) · 26 test cases · 2 s / 256 MB per case

Submitting as anonymous