传说中的数据结构

版权声明:正在学习中,有错误欢迎指出一起交流呀感谢!ヾ(✿゚▽゚)ノ https://blog.csdn.net/gx17864373822/article/details/79690372

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
	
	Scanner sc = new Scanner(System.in);
	int t = sc.nextInt();
	int i = 0;
	int a[] = new int[1010];
	String str;
	while(t-- > 0)
	{
		str = sc.nextLine();
		int len = str.length();
		if(len > 3)
		{
			i++;
			a[i] = str.charAt(len - 1) - '0';
		}
		if(str == "pop")
		{
			i--;
		}
		if(str == "top")
		{
			if(i > 0)
			{
				System.out.println(a[i]);
			}
			else 
				System.out.println("empty");
		}
	}

}

}

猜你喜欢

转载自blog.csdn.net/gx17864373822/article/details/79690372