Created
February 23, 2018 21:47
-
-
Save johirbuet/bdd3c5a5794507b89614fb94c00e4222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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