Statistics

Problem Statement for "Code"

Problem Statement

PROBLEM STATEMENT
An elementary way to encode messages is an alphabet shift.  Given an int k, you
encode a message by shifting each one of its letters by k letters to the right
in the alphabet where a is on the far left of the alphabet and z on is the far
right of the alphabet.  For example, for k=1, a becomes b, g becomes h, y
becomes z, and z becomes a (that is, it wraps around).  For k=2, a becomes c, b
becomes d, and so forth.  Given a String message and an int k, return the
alphabet-shifted message.  If there are numbers or spaces in the string, leave
them as is (see example 2).

Strings are case sensitive, so if k=1, a becomes b, and A becomes B.

DEFINITION
Class name: Code
Method name: shift
Parameters: String, int
Returns: String
The method signature is:
String shift(String message, int k)
Be sure your method is public.

TopCoder will ensure the following:
*The message will contain between 0 and 50 characters, inclusive.
*k will be an int between 0 and 25, inclusive.
*The message will contain only letters [a-z,A-Z], numbers [0-9] inclusive, and
spaces.

EXAMPLES
k = 1
message = "Hello world"
return = "Ifmmp xpsme"

k = 3
message = "Send 3 balloons"
return = "Vhqg 3 edoorrqv"

k = 0
message = "NO SHIFT"
return = "NO SHIFT"

k = 25
message = "shift me left"
return = "rghes ld kdes"

Definition

Class:
Code
Method:
shift
Parameters:
String, int
Returns:
String
Method signature:
String shift(String param0, int param1)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: