/*Sam
Panzer
*Great Neck North High School
*ACSL Contest 3 (String Manipulation)
*Intermediate 3 Division
*/
public
class ACSLStringSam
{
public static final boolean LEFT = true,
RIGHT = false;
public static void main(String [] args)
{
EasyReader
io = new EasyReader();
for(int
x = 0; x < 5; x++)
{
try
{
System.out.print("\nInput:");
String [] com =
io.readLine().split("/");
String str = com[com.length - 1];
for(int y = 0; y < com.length - 1; y++)
{
if(com[y].indexOf("LS-") != -1)
str
= lshift(str,Integer.parseInt(com[y].substring(3)));
else if(com[y].indexOf("RS-") !=
-1)
str
= rshift(str,Integer.parseInt(com[y].substring(3)));
else if(com[y].indexOf("LC-") !=
-1)
str
= lcirc(str,Integer.parseInt(com[y].substring(3)));
else if(com[y].indexOf("RC-") !=
-1)
str
= rcirc(str,Integer.parseInt(com[y].substring(3)));
else if(com[y].indexOf("MC-") !=
-1)
str
=
mcirc(str,pt(com[y].charAt(3)),pt(com[y].charAt(4)),pt(com[y].charAt(5)),com[y].charAt(6)
== 'L');
else if(com[y].indexOf("REV-") !=
-1)
str
= rev(str,pt(com[y].charAt(4)),pt(com[y].charAt(5)));
else
System.err.println("Error:
The command was not recognized");
}
System.out.println(str);
}catch(Exception
e) {System.out.println("A problem occurred.");}
//I
don't want the program to stop in the slight case of error.
}
}
//convenience method for
Integer.parseInt(String);
public static int pt(char c)
{
return
Integer.parseInt(c + "");
}
//note: all string indexes (i.e. the S/L/X)
MUST start at 1, because
//that is how the ACSL asked for it.
//executes RS-X
public static String rshift(String s, int
i)
{
String
fin = s.substring(0,s.length() -i);
for(int
x = 0; x < i; x++)
fin
= '#' + fin;
return
fin;
}
//executes LS-X
public static String lshift(String s, int
i)
{
String
fin = s.substring(i);
for(int
x = 0; x < i; x++)
fin
+= '#';
return
fin;
}
//executes RC-X
public static String rcirc(String s, int i)
{
return
s.substring(s.length() - i) + s.substring(0,s.length() - i);
}
//executes LC-X
public static String lcirc(String s, int i)
{
return
s.substring(i) + s.substring(0,i);
}
//executes MC-SLXD
public static String mcirc(String s, int
st, int l, int x, boolean d)
{
if(d
== RIGHT)
return
s.substring(0,st - 1) + rcirc(s.substring(st - 1, st + l - 1),x) +
s.substring(st + l - 1);
return
s.substring(0,st - 1) + lcirc(s.substring(st - 1, st + l - 1),x) +
s.substring(st + l - 1);
}
//executes REV-SL
public static String rev(String s, int st,
int l)
{
return
s.substring(0,st - 1) + (new StringBuffer(s.substring(st - 1, st + l -
1))).reverse() + s.substring(st + l - 1);
}