Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class CypherRoulette {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int numberOfLines = Integer.parseInt(reader.readLine());
- StringBuilder cypherString = new StringBuilder();
- String lastChars = null;
- boolean appendDirection = false;
- for (int i = 0; i < numberOfLines; i++) {
- String currentLine = reader.readLine();
- if (currentLine.equals("spin")) {
- // toggle direction
- appendDirection = !appendDirection;
- // increment because "spin" commands do not count towards the N count
- numberOfLines++;
- } else {
- if (appendDirection) {
- // insert currentLine at the beginning of cypherString
- cypherString.insert(0, currentLine);
- } else {
- // append at the end of cypherString
- cypherString.append(currentLine);
- }
- }
- if (currentLine.equals(lastChars)) {
- cypherString.delete(0, cypherString.length());
- }
- lastChars = currentLine;
- }
- System.out.println(cypherString.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement