Statistics

Problem Statement for "AlphaSeq"

Problem Statement

PROBLEM STATEMENT:

You have been assigned to a really weird problem.  Your goal is to count the
characters in a String that appear in sequence to some other character (within
the same String).

DEFINITION
Class name: AlphaSeq
Method name: numInSeq
Parameters: String, int
Returns: int
Method signature (be sure your method is public): 
int numInSeq(String text, int pos)

Let's say the input to this problem is {"WOYTA", 2}.  This is what you need to
do:
1) Find the character in the String that corresponds to the second parameter.
Assume the first character in the first parameter is position 0.  In our case,
the character in the second position is 'Y'.
2) Create a string of spaces of the same size as the original String with the
'Y' character replacing the second position - this gives us "--Y--"  (dashes
represent spaces)
3) Replace the spaces in the String from step #2 with characters in alphabetic
order from the specified character. When you do this - consider the alphabet as
a continuous loop - the character following a 'Z' is 'A' and the character
preceding the 'A' is 'Z'.  So in our case - "WX" would replace the spaces
before the "Y" and "ZA" (remember the loop rule) would replace the spaces after
the "Y" - giving us "WXYZA"
4) Compare the original string and the modified string and return the number of
characters that are in the same position in each string.  In our case we
compare "WOYTA" to "WXYZA" and see that the "W", "Y" and "A" (positions 0, 2, 4
respectively) are in the same position - so we would return 3.

TopCoder will ensure the validity of the inputs. Inputs are valid if all of the
following criteria are met:
*The text will have from 1 (one) to 50 characters (inclusive)
*The text will contain characters 'A-Z' (inclusive), (upper-case only)
*The position will point to a character in text.  If "WOYTA" was our text, then
position would be either 0,1,2,3 or 4.

Examples:
-if the input is {"ABC", 0), you should return 3
-if the input is {"ABD", 0), you should return 2
-if the input is {"ABD", 2), you should return 1
-if the input is ("ZAB", 2), you should return 3
-if the input is ("ZAC", 0), you should return 2
-if the input is ("TOPCODER",1), you should return 2
-if the input is ("TOPCODER",0), you should return 1
-if the input is ("TOPCODER",6), you should return 2
-if the input is ("TOPCODERS",8), you should return 3


Definition

Class:
AlphaSeq
Method:
numInSeq
Parameters:
String, int
Returns:
int
Method signature:
int numInSeq(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: