백준 1918번 문제인데위쪽 코드는 시간초과, 아래건 통과야

다른건 다 똑같고 getPriority함수랑
마지막 else문 안에서 priority비교하는것만 달라

도대체 무슨차이때문에 시간초과가 뜨는거야?



#include <stdio.h>
#include <stdlib.h>
#define MAX 200

int getPriority(char c)
{
    if (c == '+' || c == '-')
        return 1;
    if (c == '*' || c == '/')
        return 0;
    return -1;
}

int isOperator(char c)
{
    if (c == '+' || c == '-' || c == '*' || c == '/' || c == '(' || c == ')')
        return 1;
    else
        return 0;
}

void infixToPostfix(char *str)
{
    char stk[MAX] = {0};
    int top = 0;

    for (int i = 0; str[i]; i++)
    {
        char c = str[i];
        if (!isOperator(c))
            printf("%c", c);
        else if (c == '(')
            stk[++top] = c;
        else if (c == ')')
        {
            while (stk[top] != '(')
                if (top)
                    printf("%c", stk[top--]);
            if (top)
                top--;
        }
        else
        {
            while (top && getPriority(c) >= getPriority(stk[top]))
                printf("%c", stk[top--]);
            stk[++top] = c;
        }
    }

    while (top)
    {
        printf("%c", stk[top--]);
    }
}

int main()
{
    char infix[MAX];
    scanf("%s", infix);

    infixToPostfix(infix);

    return 0;
}



#include <stdio.h>
#include <stdlib.h>
#define MAX 200

int getPriority(char c)
{
    if (c == '+' || c == '-')
        return 0;
    if (c == '*' || c == '/')
        return 1;
    return -1;
}

int isOperator(char c)
{
    if (c == '+' || c == '-' || c == '*' || c == '/' || c == '(' || c == ')')
        return 1;
    else
        return 0;
}

void infixToPostfix(char *str)
{
    char stk[MAX] = {0};
    int top = 0;

    for (int i = 0; str[i]; i++)
    {
        char c = str[i];
        if (!isOperator(c))
            printf("%c", c);
        else if (c == '(')
            stk[++top] = c;
        else if (c == ')')
        {
            while (stk[top] != '(')
                if (top)
                    printf("%c", stk[top--]);
            if (top)
                top--;
        }
        else
        {
            while (top && getPriority(c) <= getPriority(stk[top]))
                printf("%c", stk[top--]);
            stk[++top] = c;
        }
    }

    while (top)
    {
        printf("%c", stk[top--]);
    }
}

int main()
{
    char infix[MAX];
    scanf("%s", infix);

    infixToPostfix(infix);

    return 0;
}

https://www.acmicpc.net/problem/1918