Skip to content

Instantly share code, notes, and snippets.

@johirbuet
Created February 23, 2018 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johirbuet/bdd3c5a5794507b89614fb94c00e4222 to your computer and use it in GitHub Desktop.
Save johirbuet/bdd3c5a5794507b89614fb94c00e4222 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
import java.util.Stack;
public class UVA13055 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Stack<String> stack = new Stack<>();
int T = Integer.parseInt(sc.nextLine());
for(int i = 0; i < T; i++) {
String s = sc.nextLine();
if(s.startsWith("Sleep")) {
String name = s.split(" ")[1];
stack.push(name);
} else if(s.startsWith("Test")) {
if(stack.isEmpty()) {
System.out.println("Not in a dream");
} else {
System.out.println(stack.peek());
}
} else if(s.startsWith("Kick")) {
if(!stack.isEmpty()) {
stack.pop();
}
}
}
sc.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment