Advertisement
simeonniko

Cypher Roulette

Jan 31st, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class CypherRoulette {
  6.  
  7.     public static void main(String[] args) throws IOException {
  8.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  9.  
  10.         int numberOfLines = Integer.parseInt(reader.readLine());
  11.  
  12.         StringBuilder cypherString = new StringBuilder();
  13.  
  14.         String lastChars = null;
  15.  
  16.         boolean appendDirection = false;
  17.  
  18.         for (int i = 0; i < numberOfLines; i++) {
  19.             String currentLine = reader.readLine();
  20.  
  21.             if (currentLine.equals("spin")) {
  22.                 // toggle direction
  23.                 appendDirection = !appendDirection;
  24.  
  25.                 // increment because "spin" commands do not count towards the N count
  26.                 numberOfLines++;
  27.             } else {
  28.                 if (appendDirection) {
  29.                     // insert currentLine at the beginning of cypherString
  30.                     cypherString.insert(0, currentLine);
  31.                 } else {
  32.                     // append at the end of cypherString
  33.                     cypherString.append(currentLine);
  34.                 }
  35.             }
  36.  
  37.             if (currentLine.equals(lastChars)) {
  38.                 cypherString.delete(0, cypherString.length());
  39.             }
  40.  
  41.             lastChars = currentLine;
  42.         }
  43.  
  44.         System.out.println(cypherString.toString());
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement