/*
* 两个字符串值是否相等
* 用string1.equals(string2)来判断******
*/
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
int n = input.nextInt();
input.nextLine();// 吃掉回车键
int a[] = new int[1001];
int i, k = 0;
for (i = 1; i <= n; i++) {// n次操作
// input.nextLine();//吃掉回车键
String s = input.next();//如果String s=input.nextLine();输入的是一行,则吧push要输进去的数字也包含了
//不能用input.nextLine();
if (s.equals("push")) {
a[++k] = input.nextInt();
}
else if (s.equals("top")) {
if (k != 0)
System.out.println(a[k]);
else
System.out.println("empty");
} else if (s.equals("pop")) {
if (k != 0)
k--;
else
System.out.println("error");
}
}
System.out.println();
}
}
}
传说中的数据结构
最新推荐文章于 2020-04-09 18:58:59 发布