/*
Simon Ho
Thomas Jefferson High School for Science and
Technology
Fairfax County Public Schools
Alexandria, VA, 22312
JR-5, Contest # 3, 2005-2006
LANG: JAVA
TASK: STRINGS
*/
import java.io.*;
import java.util.*;
public class ACSL3 {
static
ACSL3[] str;
String[]
mod;
char[]
op;
public
static void main (String [] args) throws IOException {
BufferedReader br = new BufferedReader(new
FileReader("ACSL3.in"));
PrintWriter out = new PrintWriter(new
BufferedWriter(new FileWriter("ACSL3.out")));
makeArrays(br, out);
out.close();
System.exit(0);
}
public
ACSL3 (ArrayList list, int index){
this.mod = new String[index-1];
for (int c =0; c<index-1; c++){
this.mod[c] = (String)list.get(c);
}
int length =
((String)list.get(index-1)).length();
this.op = new char[length];
for (int k =0; k<length; k++){
op[k] =
((String)list.get(index-1)).charAt(k);
}
}
public
static void makeArrays(BufferedReader br, PrintWriter out) throws IOException{
str = new ACSL3[5];
for (int k=0; k<5; k++){
String s = br.readLine();
StringTokenizer st = new
StringTokenizer(s, "/");
ArrayList current = new ArrayList();
int index = 0;
while (st.hasMoreTokens()){
current.add(st.nextToken());
index++;
}
System.out.println("i: "+index);
str[k] = new ACSL3(current, index);
str[k].generate(out);
}
}
public
void generate(PrintWriter out){
int length = this.mod.length;
for (int k =0; k<length; k++){
//prints current string for refference
int l = this.op.length;
for (int d =0; d<l; d++){
System.out.print(this.op[d]);
}
System.out.println();
//-----------------------------------
boolean cycle = false;
if (this.mod[k].charAt(0)!='M'){
char
dir = this.mod[k].charAt(0);
int
space = Integer.parseInt(this.mod[k].substring(3,4));
System.out.println(dir
+ "S-"+ space);
if
(this.mod[k].charAt(1)=='C'){
cycle
= true;
System.out.println("cyc");
}
this.op
= shift(this.op, dir, space, cycle);
}else {
int
start = Integer.parseInt(this.mod[k].substring(3,4)) -1;
int
len = Integer.parseInt(this.mod[k].substring(4,5));
int
rot = Integer.parseInt(this.mod[k].substring(5,6));
char
dir = this.mod[k].charAt(6);
System.out.println("MC-"+start+len+rot+dir);
this.op
= substring(this.op, start, len, rot, dir);
}
}
int l = this.op.length;
for (int d =0; d<l; d++){
System.out.print(this.op[d]);
out.print(this.op[d]);
}
System.out.println();
out.println();
}
public
char[] shift(char[] ch, char direction, int place, boolean cycle){
int length = ch.length;
//Switches direction for shift right
int start =0;
int end = length;
short inc = 1;
if (direction == 'R'){
System.out.println("--R");
start
= length-1;
place
*= -1;
end
=-1;
inc=-1;
}//------------------------------
System.out.println("p:" +
place);
char[] New = new char[length];
for (int k =start; k!=end; k+=inc){
int insert = place + k;
if (cycle){
insert%=length;
if
(insert <0){
insert
+=length;
}
}
if ((direction == 'L' && insert
< length) || (direction == 'R' && insert >= 0)){
New[k]
= ch[insert];
} else {
System.out.println("i:"+insert);
New[k]
= '#';
}
}
//prints current string for refference
int l = New.length;
System.out.print(":");
for (int d =0; d<l; d++){
System.out.print(New[d]);
}
System.out.println();
//-----------------------------------
return New;
}
public
char[] substring(char[] ch, int start, int len, int rot, char dir){
char[] raw= new char[len];
for (int k =0; k<len; k++){
raw[k] = ch[start + k];
}
char[] ins = shift(raw, dir, rot, true);
for (int k =0; k<len; k++){
ch[start+k]= ins[k];
}
return ch;
}
public
static void printResult(PrintWriter out)throws IOException{
}