怎么不对的?奇怪

P1449 后缀表达式

星之海 @ 2017-10-18 22:05:37

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int stack[10001],top=0;
void push(int x)
{
    stack[++top]=x;
}
void pop(char c)
{
    int num;
    switch(c)
{
    case '+':num=stack[top]+stack[top-1];
    case '/':num=stack[top]/stack[top-1];
    case '-':num=stack[top]-stack[top-1];
    case '*':num=stack[top]*stack[top-1];
}
    stack[--top]=0;
    stack[--top]=0;
    stack[--top]=num;
}
int main()
{
    char c;
    int n=0;
    while(scanf("%c",&c)!='@')
{
    if(c!='+'&&c!='-'&&c!='*'&&c!='/')
{
    if(c!='.')
{
    switch(c)
{
    case '1':n=n*10+1;
    case '2':n=n*10+2;
    case '3':n=n*10+3;
    case '4':n=n*10+4;
    case '5':n=n*10+5;
    case '6':n=n*10+6;
    case '7':n=n*10+7;
    case '8':n=n*10+8;
    case '9':n=n*10+9;
} 
}
    else
{
    push(n);
    n=0;
}
}
    else
    pop(c);
}
    printf("%d\n",stack[top]);
    return 0;
}

by baoligao @ 2019-11-11 18:56:33

@星之海 Did you get WA / RE / TLE / OLE / MLE / CE?


|