TopCoder problem "CardsShuffle" used in TCHS SRM 47 (Division I Level One)



Problem Statement

    

You are given a String cards, which represents a sequence of cards. Shuffle the cards by repeatedly performing the specified exchange operation. The exchange operation is specified by the ints first and last, which are both 1-based indices in the sequence. Take all the cards between the first-th card and the last-th card, inclusive, and move them to the beginning of the sequence. Do not change the relative order of the moved cards. For example, if first = 2 and last = 4, an exchange operation on "ABCDEFG" would produce "BCDAEFG".

Perform the specified exchange operation times times on the given sequence and return a String containing the resulting sequence.

 

Definition

    
Class:CardsShuffle
Method:shuffle
Parameters:String, int, int, int
Returns:String
Method signature:String shuffle(String cards, int first, int last, int times)
(be sure your method is public)
    
 

Constraints

-cards will contain between 1 and 50 characters, inclusive.
-cards will contain only uppercase letters ('A'-'Z').
-first will be between 1 and n, inclusive, where n is the number of characters in cards.
-last will be between first and n, inclusive, where n is the number of characters in cards.
-times will be between 1 and 100, inclusive.
 

Examples

0)
    
"NW"
2
2
9
Returns: "WN"
It always moves the second card to the front.
1)
    
"BMQ"
1
2
2
Returns: "BMQ"
This operation does not change anything.
2)
    
"KYHID"
3
5
8
Returns: "YHIDK"
3)
    
"YGGXXPKLO"
8
9
63
Returns: "YGGXXPKLO"
cards may contain duplicate characters.
4)
    
"KMCOQHNWNKU"
9
10
9
Returns: "COQHNWNKKMU"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8295

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10803&pm=8295

Writer:

stone

Testers:

PabloGilberto , brett1479 , Olexiy , ivan_metelsky

Problem categories:

Simple Math