为啥不开O2就能过,开O2直接RE??

P1449 后缀表达式

asdfo123 @ 2020-09-27 13:33:17

不开O_2 就能过

O_2RE

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1010;
char c[maxn];
int st[maxn];
bool comp(char *c)
{
    int i = 0;
    int now = 0;
    int top = 0;
    while(c[i]!='@')
    {
        if(c[i]>='0' && c[i]<='9')
        {
            now*=10;
            now+=c[i] - '0';
        }
        else if(c[i] == '.') 
        {
            st[++top] = now;
            now = 0;
        }
        else if(c[i] == '+')
        {
            st[top-1] = st[top-1] + st[top];
            st[top] = 0;
            top--;
        }
        else if(c[i] == '-')
        {
            st[top-1] = st[top-1] - st[top];
            st[top] = 0;
            top--;
        }
        else if(c[i] == '*')
        {
            st[top-1] = st[top-1] * st[top];
            st[top] = 0;
            top--;
        }
        else if(c[i] == '/')
        {
            st[top-1] = st[top-1] / st[top];
            st[top] = 0;
            top--;
        }
        i++;
    }   
}           
signed main()
{
    scanf("%s",c);
    comp(c);
    printf("%lld\n",st[1]);
    return 0;
}

by fisheep @ 2020-09-27 13:44:50

@Luo_Feng 没区别


by mengxiang @ 2020-09-27 13:45:03

@Luo_Feng

define int long long时的一种操作


by liuziwen0224 @ 2020-09-27 13:45:24

@Luo_Feng 当且仅当intdefinelong long了而你的主函数数要用int所以你改成了longlong


by asdfo123 @ 2020-09-27 13:46:54

@忘怀星 谢谢!


by 忘怀星 @ 2020-09-27 13:48:48

@liuziwen0224 你在 int main()上面给undef一下也行应该


by Re_Fable @ 2020-09-27 13:50:09

@忘怀星

@fishsit

@mengxiang

@liuziwen0224

谢谢 ~~~~~~~~~~~~~~ //鞠躬


by liuziwen0224 @ 2020-09-27 13:57:45

@Luo_Feng \operatorname{FAB is AKing}


上一页 |