Forum

Post 28.04.2009   # 1
Subject CodeFu 2009 Round 1 - Problem 100
100. Printer Virus

This one is pretty easy.
The StringBuffer contains a reverse() method, which makes the problem even easier.
In the following solution, first the input text is reversed, and then the three parts are rearranged to form the final output string.

public class PrinterVirus {
public String getPrintedText(String text) {
int n = text.length();
StringBuffer sb = new StringBuffer(text).reverse();
return sb.substring(2 * n / 3) + sb.substring(n / 3, 2 * n / 3) + sb.substring(0, n / 3);
}
}
bilievsk is offline Reply

Please login to post reply.