/*
import java.util.*;
interface Shape
{
final double PI = 3.14;
void draw();
double getArea();
default public void redraw()
{
System.out.println("---다시 그립니다. ");
draw();
}
}
class Circle implements Shape
{
int i;
public Circle(int i) {
this.i = i;
}
@Override
public void draw() {
// TODO Auto-generated method stub
System.out.println("반지름이" + i +" 인 원입니다.");
}
@Override
public double getArea() {
// TODO Auto-generated method stub
return PI * i*i;
}
}
class Oval implements Shape
{
int a, b;
public Oval(int a, int b) {
// TODO Auto-generated constructor stub
this.a = a;
this.b = b;
}
@Override
public void draw() {
// TODO Auto-generated method stub
System.out.println(a + "X" + b + "에 내접하는 타원입니다.");
}
@Override
public double getArea() {
// TODO Auto-generated method stub
return PI*a*b;
}
}
class Rect implements Shape
{
int i, j;
public Rect(int i, int j) {
this.i = i;
this.j = j;
// TODO Auto-generated constructor stub
}
@Override
public void draw() {
// TODO Auto-generated method stub
System.out.println(i + "X" + j + "크기의 사각형 입니다.");
}
@Override
public double getArea() {
// TODO Auto-generated method stub
return i*j;
}
}
public class Main
{
public static void main(String[] args) {
Shape [] list = new Shape[3];
list[0] = new Circle(10);
list[1] = new Oval(20,30);
list[2] = new Rect(10,40);
for(int i = 0; i < list.length; i++)
{
list[i].redraw();
}
for(int i = 0; i < list.length; i++)
{
System.out.println("면적은 " + list[i].getArea());
}
}
}
*/
import java.util.*;
interface Stack
{
int length();
int capacity();
String pop();
boolean push(String val);
}
class StringStack implements Stack
{
int x,top;
String[] save ;
public StringStack(int x) {
this.x = x;
save = new String[x];
top = 0;
}
@Override
public int length() {
return top;
}
@Override
public int capacity() {
return x;
}
@Override
public String pop() {
return save[--top];
}
@Override
public boolean push(String val)
{
if(top == x)
{
return false;
}
else
{
save[top] = val;
top++;
return true;
}
}
}
public class Main
{
public static void main(String[] args) {
int x;
String st;
Scanner s = new Scanner(System.in);
System.out.println("총 스택 저장 공간의 크기 입력 >>");
x= s.nextInt();
StringStack stst = new StringStack(x);
for(;;)
{
System.out.println("문자열 입력>>");
st = s.next();
if(st.equals("그만"))
{
break;
}
if(!stst.push(st))
{
System.out.println("스택이 꽉차서 푸시 불가!");
}
}
System.out.println("스택에 저장된 모든 문자열 팝 : ");
for(int i = 0;i < x; i++)
{
System.out.print(stst.pop()+" ");
}
}
}