TopcoderArchiveVisit Topcoder
SRM16 Jan 2002
SRM 58

Code

Problem statement, definition, constraints, and public examples.

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

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems