간단한 스택구현하는건데 비쥬얼에서 실행했을때는 잘돌아가던데 백준에 제출하니까 런타임 에러뜨네요

이렇게 간단한 것도 못짜고 자괴감 드네요 ㅠㅠ


문제 : https://www.acmicpc.net/problem/10828

어디가 문제인걸까요....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
 
namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = Convert.ToInt16(Console.ReadLine());
            Stack S = new Stack(k);
            
 
            for (int i = 0; i < k; i++)
            {
                String str= Console.ReadLine();
 
                switch (str)
                {
                    case "pop":
                        Console.WriteLine( S.pop());
                        break;
                    case "top":
                        Console.WriteLine(S.top());
                        break;
                    case "size":
                        Console.WriteLine(S.sizeOf());
                        break;
                    case "empty":
                        Console.WriteLine(S.empty());
                        break;
                    default:
                        String[] temp = str.Split(' ');
                        S.push(Convert.ToInt16(temp[1]));
                        break;
                }
            }
        }
    }
    public class Stack
    {
        public int[] data;
        int size = -1;
        public Stack(int maxdata)
        {
            data = new int[maxdata];
        }
        public void push(int input)
        {
            data[++size] = input;
        }
        public int pop()
        {
            return (size == -1) ? (-1) : (data[size--]);
        }
        public int top()
        {
            return (size == -1) ? (-1) : (data[size]);
        }
        public int empty()
        {
            return (size == -1) ? (1) : (0);
        }
        public int sizeOf()
        {
            return size+1;
        }
    }
}
cs