Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * Created by Сергей on 27.05.2016.
- */
- public class Sol {
- public static void main(String args[])
- {
- class myStack {
- int arr[];
- int size;
- myStack(){
- arr=new int[100];
- size=0;
- }
- String getCommand(String str){
- int length=str.length();
- int k=1;
- int number=0;
- if (str.charAt(0)=='p' && str.charAt(1)=='u'){
- for (int i=length-1;i>=5;i--)
- {
- number=(str.charAt(i)-'0')*k;
- k*=10;
- }
- arr[size]=number;
- size++;
- return "ok";
- }
- if (str.charAt(0)=='p' && str.charAt(1)=='o'){
- if (size==0) return "error";
- else {
- Integer a = arr[size - 1];
- size--;
- return a.toString();
- }
- }
- if (str.charAt(0)=='b' && str.charAt(1)=='a'){
- if (size==0) return "error";
- else {
- Integer a = arr[size - 1];
- return a.toString();
- }
- }
- if (str.charAt(0)=='s' && str.charAt(1)=='i'){
- Integer a=size;
- return a.toString();
- }
- if (str.charAt(0)=='c' && str.charAt(1)=='l'){
- size=0;
- return "ok";
- }
- if (str.charAt(0)=='e' && str.charAt(1)=='x'){
- return "bye";
- }
- return "WRONG";
- }
- }
- String str;
- Scanner sc=new Scanner(System.in);
- myStack st=new myStack();
- do {
- str=sc.nextLine();
- System.out.println(st.getCommand(str));
- }
- while (str!="exit");
- System.out.println(st.arr[0]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement